longjmp() from signal handler

From the man page for longjmp: POSIX does not specify whether longjmp() will restore the signal context. If you want to save and restore signal masks, use siglongjmp() Your second question: Yes, the function will return -2 because longjmp() will cause it to go to the setjmp(buffer) part, but the timing will have to be … Read more

C++: Safe to use longjmp and setjmp?

setjmp()/longjmp() completely subvert stack unwinding and therefore exception handling as well as RAII (destructors in general). From 18.7/4 “Other runtime support” in the standard: If any automatic objects would be destroyed by a thrown exception transferring control to another (destination) point in the program, then a call to longjmp(jbuf, val) at the throw point that … Read more

Practical usage of setjmp and longjmp in C

Error handling Suppose there is an error deep down in a function nested in many other functions and error handling makes sense only in the top level function. It would be very tedious and awkward if all the functions in between had to return normally and evaluate return values or a global error variable to … Read more