Skip to content

Commit 8c8bbd9

Browse files
committed
error.c: add new error handling API functions; ref #2837
- mrb_clear_error(): clear error status of mrb_state - mrb_check_error(): check if error caused in the previous API Note that `mrb_check_error` clears error status, so if you call `mrb_check_error` more than once, latter calls will return FALSE.
1 parent f5a7b6a commit 8c8bbd9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

include/mruby/error.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val)
7474
#define mrb_break_proc_get(brk) ((brk)->proc)
7575
#define mrb_break_proc_set(brk, p) ((brk)->proc = p)
7676

77+
/**
78+
* Error check
79+
*
80+
*/
81+
/* clear error status in the mrb_state structure */
82+
MRB_API void mrb_clear_error(mrb_state *mrb);
83+
/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */
84+
MRB_API mrb_bool mrb_check_error(mrb_state *mrb);
85+
7786
/**
7887
* Protect
7988
*

src/error.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,24 @@ mrb_print_error(mrb_state *mrb)
649649
#endif
650650
}
651651

652+
/* clear error status in the mrb_state structure */
653+
MRB_API void
654+
mrb_clear_error(mrb_state *mrb)
655+
{
656+
mrb->exc = NULL;
657+
}
658+
659+
/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */
660+
MRB_API mrb_bool
661+
mrb_check_error(mrb_state *mrb)
662+
{
663+
if (mrb->exc) {
664+
mrb_clear_error(mrb);
665+
return TRUE;
666+
}
667+
return FALSE;
668+
}
669+
652670
void
653671
mrb_init_exception(mrb_state *mrb)
654672
{

0 commit comments

Comments
 (0)