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)
Rules:
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.
try { /*your code here*/ } catch(Exception exception) { /* Exeption caught if something goes wrong*/ } finally { /*Guaranteed to run even if exception occurs.This block will always run*/ Console.WriteLine(); /* * Clean UP Code. */ }
Reblogged this on Dinesh Ram Kali..
LikeLike