Jump to content

Microsoft-specific exception handling mechanisms

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 81.5.117.93 (talk) at 17:13, 21 November 2009 (Structured Exception Handling). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Microsoft Windows OS family employs some exception handling mechanisms that are based on the operation system specifics.

Structured Exception Handling

Microsoft Structured Exception Handling is the native exception handling mechanism for Windows and a forerunner technology to VEH.[1] It features the finally mechanism not present is standard С++ exceptions (but present in most imperative languages introduced later).

SEH mechanism is per-thread and needs to be set up for each thread of execution separately.

Usage

SEH is officially supported on compiler level. MS Visual C++ compiler introduces 3 non-standard keywords: __try, __except and __finally — for this purpose. There is a Win32-specific function RaiseException to raise exceptions manually (replacing the C++ throw statement) and some auxiliary functions[2] too.

Implementation

Each thread of execution in Windows has an undocumented _EXCEPTION_REGISTRATION_RECORD list at the start of its Thread Information Block. The __try statement essentially calls a compiler-defined EH_prolog function. That function allocates an _EXCEPTION_REGISTRATION_RECORD pointing to __except_handler3 function in msvcrt.dll, then adds the record to the list's head. At the end of the __try block a compiler-defined EH_epilog function is called that does the reverse. Any of the compiler-defined routines can be inline. All the programmer-defined __except blocks are called from within __except_handler3. If such blocks are present,

In a case of an exception, the operating system[3] parses the thread's _EXCEPTION_REGISTRATION_RECORD list and calls each exception handler in sequence. If a handler returns EXCEPTION_EXECUTE_HANDLER, it has handled the exception, the program's execution

  • Microsoft Corp. (11/12/2009). "Structured Exception Handling". MSDN Library. Retrieved 2009-11-17. {{cite web}}: Check date values in: |date= (help)
  • Matt Pietrek (Jan 1997). "A Crash Course on the Depths of Win32™ Structured Exception Handling". MSJ. 12 (1).
  • Igor Skochinsky (Monday, March 6 2006 12:02.38 CST). "Reversing Microsoft Visual C++ Part I: Exception Handling". OpenRCE. Retrieved 2009-11-17. {{cite web}}: Check date values in: |date= (help)

Vectored Exception Handling

Vectored Exception Handling was introduced with Windows XP. [4] Vectored Exception Handling is made available to Windows programmers using languages such as C++ and Visual Basic. VEH does not replace Structured Exception Handling (SEH), rather VEH and SEH coexist, with VEH handlers having priority over SEH handlers.[4][1] Compared with SEH, VEH works more like a traditional notification callback scheme.[5]

Use of VEH

Use AddVectoredExceptionHandler API

References

  1. ^ a b "Vectored Exception Handling in Windows Server 2003 (Through Internet Archive)". Cite error: The named reference "devx" was defined multiple times with different content (see the help page).
  2. ^ Microsoft Corp. (11/12/2009). "Structured Exception Handling Functions". MSDN Library. Retrieved 2009-11-17. {{cite web}}: Check date values in: |date= (help)
  3. ^ More specifically, the KiDispatchException kernel routine
  4. ^ a b "New Vectored Exception Handling in Windows XP".
  5. ^ "Windows Server 2003 Discover Improved System Info, New Kernel, Debugging, Security, and UI APIs".