Created
July 21, 2017 19:37
-
-
Save paniq/d2d499101b0cf23faae2ffc4690fb73f 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
struct ExceptionPad { | |
jmp_buf retaddr; | |
Exception exc; | |
void invoke(const Exception &exc) { | |
this->exc = exc; | |
longjmp(retaddr, 1); | |
} | |
}; | |
#define SCOPES_TRY() \ | |
ExceptionPad exc_pad; \ | |
ExceptionPad *_last_exc_pad = _exc_pad; \ | |
_exc_pad = &exc_pad; \ | |
if (!setjmp(exc_pad.retaddr)) { | |
#define SCOPES_CATCH(EXCNAME) \ | |
_exc_pad = _last_exc_pad; \ | |
} else { \ | |
_exc_pad = _last_exc_pad; \ | |
auto &&EXCNAME = exc_pad.exc; | |
#define SCOPES_TRY_END() \ | |
} | |
static ExceptionPad *_exc_pad = nullptr; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment