반응형
https://github.com/linuxias/linux-system-programming/blob/master/exception/try-catch.c
#include <stdio.h> | |
#include <setjmp.h> | |
#define TRY \ | |
do { \ | |
jmp_buf __buf; \ | |
switch (setjmp(__buf)) { \ | |
case 0: \ | |
{ | |
#define CATCH(e) \ | |
break; \ | |
} \ | |
case e: { | |
#define FINALLY \ | |
break; \ | |
} \ | |
default: { | |
#define ETRY \ | |
} \ | |
} \ | |
} while(0); | |
#define THROW(e) longjmp(__buf, e) | |
#define EXCEPTION_1 1 | |
#define EXCEPTION_2 2 | |
int main() | |
{ | |
TRY { | |
printf("try\n"); | |
THROW(EXCEPTION_2); | |
printf("try check\n"); | |
} CATCH (EXCEPTION_1) { | |
printf("Exception1 !!\n"); | |
} CATCH (EXCEPTION_2) { | |
printf("Exception2 !!\n"); | |
} ETRY; | |
return 0; | |
} |
반응형
'Language > C,C++' 카테고리의 다른 글
[C] #pragma pack( [show] | [push | pop] , n ) (0) | 2018.07.06 |
---|---|
[C++] atomic_flag (0) | 2018.06.26 |
[C언어] 실수형 MAX, MIN 값 (0) | 2017.11.05 |
[C] noreturn (0) | 2015.11.29 |
[C언어] Header File 한번만 포함하기. (0) | 2015.09.13 |