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:
Yukihiro "Matz" Matsumoto
2023-02-03 13:41:10 +09:00
parent f5a7b6aad2
commit 8c8bbd94dc
2 changed files with 27 additions and 0 deletions
+9
View File
@@ -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
View File
@@ -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)
{