Submitted by: Srinath M S(srinath_ms@yahoo.com)

Monday Sep 17th 2018 by Srinath M S

Language: .NET, Expertise: Intermediate - See how to filter for conditional exceptions in C#.

There are cases in which we want to ignore errors even if they are genuine. For example, there could be a feed running on all days except for some fixed holidays. You could work with the exception as shown below.

The following code catches the null reference exception only when it is not a pre-defined holiday (through the IsHoliday method).





catch(System.NullReferenceException ex) if (!IsHoliday(DateTime.Now))


//log this error

Mobile Site | Full Site