Better way to ignore exception type: multiple catch block vs. type querying
- by HuBeZa
There are situations that we like to ignore a specific exception type (commonly ObjectDisposedException). It can be achieved with those two methods:
try
{
// code that throws error here:
}
catch (SpecificException) { /*ignore this*/ }
catch (Exception ex)
{
// Handle exception, write to log...
}
or
try
{
// code that throws error here:
}
catch (Exception ex)
{
if (ex is SpecificException) { /*ignore this*/ }
else
{
// Handle exception, write to log...
}
}
What are the pros and cons of this two methods (regarding performance, readability, etc.)?