ERR52-CPP. Do not use setjmp() or longjmp()
The C standard library facilities setjmp() and longjmp() can be used to simulate throwing and catching exceptions. However, these facilities bypass automatic resource management and can result in undefined behavior , commonly including resource leaks and denial-of-service attacks .
The C++ Standard, [support.runtime], paragraph 4 [ ISO/IEC 14882-2014 ], states the following :
The function signature
longjmp(jmp_buf jbuf, int val)has more restricted behavior in this International Standard. Asetjmp/longjmpcall pair has undefined behavior if replacing thesetjmpandlongjmpbycatchandthrowwould invoke any non-trivial destructors for any automatic objects.
Do not call setjmp() or longjmp() ; their usage can be replaced by more standard idioms such as throw expressions and catch statements.