Skip to content

Instantly share code, notes, and snippets.

@paniq
Created July 21, 2017 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paniq/d2d499101b0cf23faae2ffc4690fb73f to your computer and use it in GitHub Desktop.
Save paniq/d2d499101b0cf23faae2ffc4690fb73f to your computer and use it in GitHub Desktop.
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