Using Marshal.GetExceptionCode()

July 1, 2007

Ayende excitedly points out that from within a finally block, you can determine whether an exception was thrown or not; in the comments, he goes on to explore how useful this may be. Let's begin with noting that Marshal.GetExceptionCode is likely implemented in terms of the VC compiler intrinsic, _exception_code which is exposed through the GetExceptionCode macro.  This VC intrinsic can only be used from within the filter expression of an exception filter, or from within the exception handler's block (and it is enforced by the compiler).  However, you can call Marshal.GetExceptionCode from anywhere in your program, and it's...
no comments