IS NOT operator in C#
In this case, wrap and check the boolean opposite:
if (!(err is ThreadAbortException))
Just change the catch block to:
catch(ThreadAbortException ex)
{
}
catch(Exception ex)
{
}
so you can handle ThreadAbortExceptions and all others separately.
More than likely what you ought to do in this circumstance is:
try
{
// Do Something
}
catch (ThreadAbortException threadEx)
{
// Do something specific
}
catch (Exception ex)
{
// Do something more generic
}
You can have multiple catch
blocks for a try
. Always make sure to order them such that the most specific is on top, and the most generic (catch (Exception ex)
) is last because the lookup order is from top to bottom, so if you put the catch (Exception ex)
first, it will always be the only one to run.