Are the e.HResult of the exceptions in c # unique?


I want to know if each e.HResult that gives an exception is unique and that as such it is always the same.

Or else how could I validate a specific exception always? My problem is that I need an exception which tells me that it is not possible to connect to the internet (briefly) and the e.HResult is always -2146233087 but I do not know if This e.HResult is always the same or can change

Greetings and thanks

asked by Alejo Florez 10.11.2017 в 16:05

1 answer


According to microsoft :


HRESULT is a 32-bit value, divided into three different fields: a   severity code, an installation code and an error code. The   Severity code indicates whether the return value represents   information, warning or error. The installation code identifies   the area of the system responsible for the error. The error code is a   unique number that is assigned to represent the exception. Each   exception is assigned to a different HRESULT.

Notice that it says to each exception, not to each type of exception what is different. In your case always return the same codes because you are returning the same error on the same circumstances which causes the same code is always created. Now, if the circumstances vary, then the error code would be different.

Wikipedia explains in more detail what each portion of the code means.

So I, you, trust me with the exception type, not the code HRESULT .

answered by 10.11.2017 / 16:17