Last active
May 7, 2021 19:42
-
-
Save ericsonj/2b799a0abe922a9d617db926deff68c8 to your computer and use it in GitHub Desktop.
c_exceptions_handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Exceptions.h" | |
FILE* fd = NULL; | |
TRY { | |
// try open file and do something | |
fd = fopen("file.txt", "r"); | |
THROW_IF_FAIL(fd != NULL, Exception); | |
// more lines | |
} CATCH(ex, Exception) { | |
// Jump to here from any invalid THROW_IF_FAIL | |
printf("error"); | |
} FINALLY { | |
// If all is OK or NOT, run finally | |
if (fd != NULL) { | |
close(fd); // Close file | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment