Created
April 6, 2013 14:48
-
-
Save chaitanyav/5326340 to your computer and use it in GitHub Desktop.
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
/* | |
* Author: NagaChaitanya Vellanki | |
* | |
* TRY/THROW/CATCH example | |
* Reference: http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html | |
* use gcc -E -P exception_handling_1.c to the output of the preprocessor | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <setjmp.h> | |
#define TRY do{ jmp_buf env; if(!setjmp(env)) { | |
#define CATCH } else { | |
#define END_TRY } }while(0) | |
#define THROW longjmp(env, 1) | |
int main(int argc, char *argv[]) { | |
TRY { | |
printf("In TRY statement\n"); | |
THROW; | |
printf("not reachable\n"); | |
} | |
CATCH { | |
printf("exception caught\n"); | |
} | |
END_TRY; | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment