C# Exception FiltersC# 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 SyntaxIn the following example, we are implementing exception filter. It executes only, if compiler throws an IndexOutOfRangeException exception. C# Exception Filter ExampleOutput A new task is executing... In the following example, we are throwing exception explicitly that matches with when condition. C# Exception Filter Example2Output Array Exception Occured A new task is executing... Next TopicC# Await |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India