Catch Error : Exception Try Catch : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Try Catch »

 

Catch Error








    


using System;

public class CatchError
{
    public static void Main()
    {
        int var1 = 1000, var2 = 0, var3;

        try
        {
            var3 = var1 / var2;
        }
        catch (ArithmeticException e)
        {
            Console.WriteLine("Exception: {0}", e.ToString());
            var3 = -1;
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: {0}", e.ToString());
            var3 = -2;
        }
        Console.WriteLine("The result is: {0}", var3);
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Try Catch