...
The following example uses setjmp()
and longjmp()
to ensure that control flow is disrupted in the event of error, and also uses the my_errno
indicator from the previous example. See MSC22-C. Use the setjmp(), longjmp() facility securely for more info on setjmp()
and longjmp()
.
Code Block | ||
---|---|---|
| ||
#include <setjmp.h> const errno_t ESOMETHINGREALLYBAD = 1; jmp_buf exception_env; void g(void) { /* ... */ if (something_really_bad_happens) { longjmp(exception_env, ESOMETHINGREALLYBAD); } /* ... */ } void f(void) { g(); /* ... do the rest of f ... */ } /* ... */ if (setjmp(exception_env) != 0) { /* if we get here, an error occurred; do not continue processing */ } /* ... */ f(); /* if we get here, no errors occurred */ /* ... */ |
...