O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

setjmp, longjmp

Languages like C++ and Java have exception-handling features built in. This is where code can happily go about its business, ignoring anything that might go wrong with the functions it is calling. But if something does go wrong, an exception can be thrown which will terminate the current flow of execution. Control resumes execution at a previously registered exception handler, which can then decide how best to recover from the problem and resume the work.

C has a primitive form of exception handling that can be used in a similar manner. The setjmp and longjmp functions are used like a super-goto:

int setjmp (jmp_buf env);

void longjmp (jmp_buf env, int value);

jmp_buf is a data structure that holds the current execution context ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required