In the context of the C language (and other languages like C++), SJLJ, DWARF, and SEH are different models of exception handling and unwinding, particularly used in compilers and runtimes.
Here's a breakdown of these exception-handling mechanisms:
- Full Name: Setjmp/Longjmp exception handling.
- How It Works: This model is based on the C standard library functions
setjmp()
and longjmp()
. It works by saving the state of the stack and registers in a jmp_buf
structure when an exception is expected (via setjmp
), and restoring it later when an exception is thrown (via longjmp
).
- Performance: It tends to have a low cost in normal execution because no metadata is generated to handle exceptions, but higher cost when an exception occurs, as it requires a full context switch.
- Platform Support: SJLJ is very portable and can work across many different systems.
- Common Use: Historically used in some older versions of G