Created
September 24, 2011 12:08
-
-
Save autumnharmony/1239254 to your computer and use it in GitHub Desktop.
Exceptions in C with Longjmp and Setjmp
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 <stdio.h> | |
#include <setjmp.h> | |
#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){ | |
#define CATCH } else { | |
#define ETRY } }while(0) | |
#define THROW longjmp(ex_buf__, 1) | |
int | |
main(int argc, char** argv) | |
{ | |
TRY | |
{ | |
printf("In Try Statement\n"); | |
THROW; | |
printf("I do not appear\n"); | |
} | |
CATCH | |
{ | |
printf("Got Exception!\n"); | |
} | |
ETRY; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment