How to determine if an exception is of a particular type

前端 未结 5 1095
Happy的楠姐
Happy的楠姐 2021-02-01 00:21

I have a piece of try catch code:

try 
{
    ...
}
catch(Exception ex) 
{
    ModelState.AddModelError(
        \"duplicateInvoiceNumberOrganisation\", \"The com         


        
5条回答
  •  一生所求
    2021-02-01 00:50

    Replace System.Threading.ThreadAbortException with your exception.

    try
    {
        //assume ThreadAbortException occurs here
    }
    catch (Exception ex)
    {
        if (ex.GetType().IsAssignableFrom(typeof(System.Threading.ThreadAbortException)))
        {
             //what you want to do when ThreadAbortException occurs         
        }
        else
        {
             //do when other exceptions occur
        }
    }
    

提交回复
热议问题