Menu

Sunday, 30 November 2014

Exception Filters in C# 6.0


This feature helps to filter the exception messages by providing conditional statements which returns true or false at catch block.

Suppose, if you want to log the exception in catch block only if inner exception is not null. In that scenario, you can write the code like the below.
 So, In the catch block if condition returns true then it enters into the catch block and it would log and throws the exception.
try  
{  
   //Some Exception Throws  
}  
catch(Exception ex) if(ex.InnerException != null)  
{  
   //Log the Exception and throw  
   throw;  
}  
finally  
{  
}  

No comments:

Post a Comment