Treat Exception by Code

6

In Visual Basic 6 there was the err.number command where the error code occurred.

I have a C # application that treats exception for the message description because I can not find the command that returns the error code. I have a problem because one of the machines has been changed the operating system the exception message is returning in English and the treatment I have is in Portuguese.

Is there a command that returns the error code?

I checked that there is one that displays the type of the error, but I understand it can be a set of errors related to the type.

    
asked by anonymous 10.04.2018 / 19:01

2 answers

6

I believe you want the property HResult , it is the only form of code available in all exceptions. But honestly if you need this information, you are most likely doing something wrong, the exceptions themselves are enough to classify the error.

There are cases where the code may be relevant, perhaps the largest example is SQLException ", which has the property ErrorCode that exactly takes the HRESULT in a more semantic way. An example .

Exception handling in C # is different from VB error handling, learn to use idiomatically. Alias I suggest you study deeply the exception handling that is very often used in the wrong way.

    
10.04.2018 / 19:20
4

You can use the command:

int code = System.Runtime.InteropServices.Marshal.GetExceptionCode();

It will return the Exception code you are looking for

    
10.04.2018 / 19:06