...
| Code Block | ||
|---|---|---|
| ||
const errno_t ESOMETHINGREALLYBAD = 1;
errno_t g(void) {
/* ... */
if (something_really_bad_happens) {
return ESOMETHINGREALLYBAD;
}
/* ... */
return 0;
}
errno_t f(void) {
errno_t status = g();
if ((status = g()) != 0)
return status;
/* ... do the rest of f ... */
return 0;
}
|
...
| 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 ... */
}
/* ... */
errno_t err;
if ((err = setjmp(exception_env));
if (err != 0) {
/* if we get here, an error occurred
and err indicates what went wrong */
}
/* ... */
f();
/* if we get here, no errors occurred */
/* ... */
|
...