2 ** mruby/throw.h - mruby exception throwing handler
4 ** See Copyright Notice in mruby.h
10 #if defined(MRB_ENABLE_CXX_ABI)
11 # if !defined(__cplusplus)
12 # error Trying to use C++ exception handling in C code
16 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
18 #define MRB_TRY(buf) try {
19 #define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; }
20 #define MRB_END_EXC(buf) }
22 #define MRB_THROW(buf) throw((buf)->impl)
23 typedef mrb_int mrb_jmpbuf_impl;
29 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
30 #define MRB_SETJMP _setjmp
31 #define MRB_LONGJMP _longjmp
33 #define MRB_SETJMP setjmp
34 #define MRB_LONGJMP longjmp
37 #define MRB_TRY(buf) if (MRB_SETJMP((buf)->impl) == 0) {
38 #define MRB_CATCH(buf) } else {
39 #define MRB_END_EXC(buf) }
41 #define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
42 #define mrb_jmpbuf_impl jmp_buf
49 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
50 static mrb_int jmpbuf_id;
51 mrb_jmpbuf() : impl(jmpbuf_id++) {}
55 #endif /* MRB_THROW_H */