When using Marshal.GetExceptionCode() how do you get the Exception Type and/or instance of the exception?
A:
I believe you want GetExceptionForHR, but it is only available for .NET 2.0 and above.
Mark Hurd
2010-04-01 06:39:38
A:
That's not how it works. Marshal.GetExceptionCode only returns a meaningful number if the CLR has caught an SEH exception. It will try to translate the exception into a meaningful managed exception. The common ones are NullReferenceException, OverflowException, DivideByZeroException, StackOverflowException, AccessViolationException. SEHException is the fall-back one.
You can call GetExceptionCode while handling one of those exceptions. Chicken-and-egg, the managed exception gets raised first.
Hans Passant
2010-04-02 18:35:36