I have a need to check if an exception is within a list of specified exceptions and currently my code looks like:
catch (Exception ex) {
if ( (ex is Exception1) || (ex is Exception2) || (ex is Exception3) || (ex is Exception4) || (ex is Exception5) ) {
//do something;
}
}
As you can see the syntax is not very elegant. Is there a better/cleaner way to write this type of expression in C#?
Edit - I was looking for some better build in syntax to treat Exceptions as types so maybe I can build a list of these exceptions and just use something like if a list object includes this ex. Anyway, I think I can bear with the current code for now.