#46 Exception Handling Mechnaism

C# Provides try,catch and finally mechanism to handle Exception.

try: Business logic code block,potentially might cause exception 

catch: Block where all your exceptions are caught.

Finally:Block which always executes after try/catch irrespective of exceptions.( P.S: Stackoverflow will make the finally block not to execute)


1.There must be finally block after try,If you do not have a catch block.

2.There can be two or more catch blocks.

3.Ordering of Catching Exception Matters.

4.Exception is the base of all other ExceptionClasses.

 /*your code here*/
 catch(Exception exception)
 /* Exeption caught if something goes wrong*/
 /*Guaranteed to run even if exception occurs.This block will always run*/
 * Clean UP Code.

One thought on “#46 Exception Handling Mechnaism

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s