How to get Exception Error Code in C#

前端 未结 5 1160
心在旅途
心在旅途 2020-11-30 08:57
try
{
     object result = processClass.InvokeMethod(\"Create\", methodArgs);
}
catch (Exception e)
{  
    // Here I was hoping to get an error code.
}
5条回答
  •  攒了一身酷
    2020-11-30 09:28

    Another method would be to get the error code from the exception class directly. For example:

    catch (Exception ex)
    {
        if (ex.InnerException is ServiceResponseException)
           {
            ServiceResponseException srex = ex.InnerException as ServiceResponseException;
            string ErrorCode = srex.ErrorCode.ToString();
           }
    }
    

提交回复
热议问题