This documentation is archived and is not being maintained.

Using setjmp/longjmp

Do not use setjmp and longjmp in C++ programs; these functions do not support C++ object semantics. Also, using these functions in C++ programs may degrade performance by preventing optimization on local variables. Use the C++ exception handling try/catch constructs instead.

If you must use setjmp/longjmp in a C++ program, the interaction between these functions and C++ exception handling requires that you include SETJMP.H or SETJMPEX.H. Destructors for local objects will be called during the stack unwind if you compile with /EH. If you compile with /EHs and one of your functions call a function that uses nothrow, and if the function that uses nothrow calls longjmp, the destructor unwind may not occur, depending on the optimizer.

Also, if you intend your code to be portable, do not rely on correct destruction of frame-based objects when executing a nonlocal goto using a call to longjmp.