I have a web service. Within a method, I have a try-catch block. Then within it, I would like to get the exception code.
I have tried below:
catch (Exception e){
var w32ex = e as Win32Exception;
if(w32ex == null) {
w32ex = e.InnerException as Win32Exception;
}
if(w32ex != null) {
int code = w32ex.ErrorCode;
// do stuff
}
// do other stuff
}
... that is explained here but in my case, it is not working: When casting exception e as Win32Exception I get a null and also once I get a null and I try to cast e.InnerException
as Win32Exception
I get null as well.
Below a screenshot with my exception:
As you can see there is a HResult
code.