diff --git a/include/mruby/error.h b/include/mruby/error.h index ccf2cdb6e..16e9305cc 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -74,6 +74,15 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val) #define mrb_break_proc_get(brk) ((brk)->proc) #define mrb_break_proc_set(brk, p) ((brk)->proc = p) +/** + * Error check + * + */ +/* clear error status in the mrb_state structure */ +MRB_API void mrb_clear_error(mrb_state *mrb); +/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */ +MRB_API mrb_bool mrb_check_error(mrb_state *mrb); + /** * Protect * diff --git a/src/error.c b/src/error.c index a0e23fad4..1e74f6c46 100644 --- a/src/error.c +++ b/src/error.c @@ -649,6 +649,24 @@ mrb_print_error(mrb_state *mrb) #endif } +/* clear error status in the mrb_state structure */ +MRB_API void +mrb_clear_error(mrb_state *mrb) +{ + mrb->exc = NULL; +} + +/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */ +MRB_API mrb_bool +mrb_check_error(mrb_state *mrb) +{ + if (mrb->exc) { + mrb_clear_error(mrb); + return TRUE; + } + return FALSE; +} + void mrb_init_exception(mrb_state *mrb) {