Nesting of Exceptions & try catch blocks C# with Example



Nesting of Exceptions & try catch blocks C# with Example

One is able to nest one exception / try catch block inside the other. 
This way one can manage small blocks of code which are capable of working without disrupting your whole 
mechanism. 
try 
{ 
//some code here 
try 
{ 
//some thing which throws an exception. For Eg : divide by 0 
} 
catch (DivideByZeroException dzEx) 
{ 
//handle here only this exception 
//throw from here will be passed on to the parent catch block 
} 
finally 
{ 
//any thing to do after it is done. 
} 
//resume from here & proceed as normal; 
} 
catch(Exception e) 
{ 
//handle here 
} 
Note: Avoid Swallowing Exceptions when throwing to the parent catch block 
 

0 Comment's

Comment Form

Submit Comment