FILE *fopen_ex (const char *file, const char *mode) {
FILE *fp = fopen (file, mode);
if (!fp)
Throw (EFOPEN);
return fp;
}
/* If a catch statement is required before finally,
* just add something like:
*
* } CatchAny {
* Rethrow ();
*/
int fun (void) {
FILE *in, *out;
int ret;
Try {
in = fopen_ex ("input", "r");
Try {
out = fopen_ex ("output", "w");
/* ... do something ... */
fclose (out);
} Finally {
fclose (in);
}
ret = OK;
} CatchAny {
ret = ERROR;
}
/* Well, yes, this function doesn't really need to return any value,
* since hey, we have exceptions now, but let's keep the interface. */
return ret;
}
Comments
Use e-mail, webchat, or the form below. I'll also pick up on new HN, Lobsters, and Reddit posts.