What is the best way to exclude an exception type from your catch? You may not know what types of exceptions are coming in so one of your catch may be the generic catch(Exception ex) , and you could easily check the type of that exception and if it matches the one you want to exclude, then throw it back up, but im guessing that is very inefficient. Is there a better way to do it?
The most straightforward way would be to have a block for the kind of exception you don't want to catch:
try {
// ....
} catch (DoNotWantToCatchException) {
throw;
} catch (Exception ex) {
// Handle exception
}
There isn't any simpler way to accomplish your requirement.
Very strange requirement. But you can catch this particular exception type and re-throw it
try
{
// code
}
catch(YourSpecificException e)
{
throw;
}
// catch other exceptions here (which you want to handle)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With