Throw Exception in finally statement : Exception Throw « Language Basics « C# / CSharp Tutorial






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" );
        }
    }
}
Cleaning up...
Done








1.22.Exception Throw
1.22.1.Manually throw an exception.
1.22.2.Rethrow an exception
1.22.3.Throw Exception from a function
1.22.4.Wrap exception in another one, adding additional context
1.22.5.Throw Exception in finally statement
1.22.6.Creating and throwing an exception object