A try, catch, and finally block without Exception class declaration : Try Catch : Language Basics C# Examples


C# Examples » Language Basics » Try Catch »

 

A try, catch, and finally block without Exception class declaration









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {

        try
        {
            int  zero  =  0;
            Console.WriteLine("In  try  block:  attempting  division  by  zero");
            int  myInt  =  1  /  zero;
            Console.WriteLine("You  never  see  this  message!");

        }
        catch
        {
            Console.WriteLine("In  catch  block:  an  exception  was  thrown");

        }
        finally
        {
            Console.WriteLine("In  finally  block:  do  any  cleaning  up  here");
        }
    }
}
    
   
  
   



Output

In try block: attempting division by zero
In catch block: an exception was thrown
In finally block: do any cleaning up here


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Try Catch