5

How do I get the type of Win32Exception, and classify it into something more specific? The message is only (arguably) good for showing it to the user.

  • Should I use Win32Exception.ErrorCode, Win32Exception.HResult, or Win32Exception.NativeErrorCode?
  • Are there any built-in enumerations for these codes?
Andrey Moiseev
  • 3,914
  • 7
  • 48
  • 64
  • 3
    NativeErrorCode returns the underlying winapi error code. Enumerated in the SDK's WinError.h file and many web sites. There are many of them, you have to know up front which one you are going to "handle". As always, only swallow exceptions when you know how to restore program state and take corrective action that doesn't require the user to help. Not common. – Hans Passant Nov 23 '16 at 14:48

1 Answers1

5

It seems that to classify Win32Exception you should use use both:

The exception message is a culture-specific translation of system error code, so don't use it. There are no built-in .NET classes for the mentioned values, you have to make your own.

Example: how to catch a specific "The system cannot find the file specified" kind of Win32Exception.

Community
  • 1
  • 1
Andrey Moiseev
  • 3,914
  • 7
  • 48
  • 64