How to determine if an exception is of a particular type

前端 未结 5 1093
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:42

    To get name of the exception you can use

        catch (Exception exc){
           if (exc.GetType().FullName == "Your_Exception") 
           {
              // The same can be user for InnerExceptions
              // exc.InnerException.GetType().FullName
           }
       }
    

提交回复
热议问题