Home » C# finally

C# finally

C# finally block is used to execute important code which is to be executed whether exception is handled or not. It must be preceded by catch or try block.

C# finally example if exception is handled

Output:

System.DivideByZeroException: Attempted to divide by zero. Finally block is executed Rest of the code 

C# finally example if exception is not handled

Output:

Unhandled Exception: System.DivideBy 

You may also like