I have a method that checks the exception passed in and returns a bool value.
Currently my implementation is like this
private bool ExceptionShouldNotify(Exception e)
{
return
e is FirstCustomException ||
e is SecondCustomException ||
e is ThirdCustomException ||
e is FourthCustomException ||
e is FifthCustomException ||
e is SixthCustomException ||
e is SeventhCustomException;
}
However is it better performance-wise to use a dictionary lookup rather than several OR
statements and the is
check?
Something like this:
private bool ExceptionShouldNotify(Exception e)
{
var dict = new Dictionary<String, int> {
{ "FirstCustomException", 1 },
{ "SecondCustomException", 1 },
{ "ThirdCustomException", 1 },
{ "FourthCustomException", 1 },
{ "FifthCustomException", 1 },
{ "SixthCustomException", 1 },
{ "SeventhCustomException", 1 }
};
return dict.ContainsKey(e.GetType().Name);
}