C examples for setjmp.h:setjmp
macro
<setjmp.h> <csetjmp>
Save calling environment for long jump
int setjmp (jmp_buf env);
fills env with information about the current state of the calling environment
Parameter | Description |
---|---|
env | Object of type jmp_buf where the environment information is stored. |
This macro may return more than once.
On its direct invocation, it always returns zero.
When longjmp is called, the macro returns the value passed to longjmp as second argument if this is different from zero, or 1 if it is zero.
#include <stdio.h> #include <stdlib.h> #include <setjmp.h> int main()// ww w . ja va 2 s . c o m { jmp_buf env; int val; val = setjmp (env); if (val) { fprintf (stderr,"Error %d happened",val); exit (val); } longjmp (env,101); /* signaling an error */ return 0; }