mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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.
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
+18
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user