Throw Exception in finally statement : Exception Throw : Language Basics C# Examples


C# Examples » Language Basics » Exception Throw »

 

Throw Exception in finally statement









    
using  System;
using  System.Collections;

public  class  MainClass
{
        static  void  Main()  {
                try  {
                        try  {
                                ArrayList  list  =  new  ArrayList();
                                list.Add(  1  );

                                Console.WriteLine(  "Item  10  =  {0}",  list[10]  );
                        }
                        finally  {
                                Console.WriteLine(  "Cleaning  up..."  );
                                throw  new  Exception(  "I  like  to  throw"  );
                        }
                }
                catch(  ArgumentOutOfRangeException  )  {
                        Console.WriteLine(  "Oops!    Argument  out  of  range!"  );
                }
                catch  {
                        Console.WriteLine(  "Done"  );
                }
        }
}
    
   
  
   



Output

Cleaning up...
Done


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Exception Throw