Posts

Showing posts with the label #C# #ExceptionFilters

C# Exception Filters

C# Exception Filters is a feature of C# programming language. It is introduced in version C# 6.0. It allows us to specify condition along with a catch block. C# provides  when  keyword to apply a condition (or filter) along with catch block. A catch block will execute only when the condition is  true . If the condition is  false , catch block is skipped and compiler search for next catch handler. C# Exception Filters is used for logging purpose. C# Exception Filter Syntax catch  (ArgumentException e) when (e.ParamName ==  "?" ){  }     In the following example, we are implementing exception filter. It executes only, if compiler throws an  IndexOutOfRangeException  exception. C# Exception Filter Example using  System;   namespace  CSharpFeatures   {        class  ExceptionFilter       {    ...