Structured Exception Handling (C)

The typical code spends about ninety percent of its time handling conditions that occur less than one percent of the time. Structured Exception Handling (SEH) allows you to write code that concentrates on the normal case and relegates anomalous conditions to an exception handler. The programmer will spend more of their time focused on the code that actually does what the function is supposed to do rather than clutter the output with checking for exceptional cases.

There are several differences between Structured Exception Handling and C++ Exception handling. The differences are summarized below:

signal(handler);
  • most portable, defined by ANSI
  • works in C or C++
  • non-resumptive
  • only give access to a subset of system exceptions
  • handler is a separate function
#pragma handler(x)
  • available on Win32 and OS/2
  • works in C or C++
  • resumptive or non-resumptive
  • can catch any system exception
  • handler is a separate function
SEH
  • available only on Win32, nonportable
  • works only in C
  • resumptive or non-resumptive
  • can catch any system exception
  • handler is a separate function
  • is always of type "unsigned int"
C++ throw/catch
  • portable, defined by ANSI
  • works only in C++
  • non-resumptive
  • can only catch C++ throws, no system exceptions
  • handler has access to local variables
  • can be of any type

There are two types of exception handling in SEH. They are Termination handling and Exception handling.



Termination Handler
Exception Handler