Header: mruby/error.h
Overview
mruby error handling.
Function Summary collapse
- mrb_noreturn mrb_sys_fail(mrb_state *, const char *)
- mrb_value mrb_exc_new_str(mrb_state *, struct RClass*, mrb_value)
- mrb_noreturn mrb_no_method_error(mrb_state *, mrb_sym, mrb_value, const char *, ...)
-
void mrb_clear_error(mrb_state *)
clear error status in the mrb_state structure.
-
mrb_bool mrb_check_error(mrb_state *)
returns TRUE if error in the previous call; internally calls mrb_clear_error().
- mrb_value mrb_protect_error(mrb_state *, mrb_protect_error_func *, void *, mrb_bool *)
-
mrb_value mrb_protect(mrb_state *, mrb_func_t, mrb_value, mrb_bool *)
Protect (takes mrb_value for body argument).
-
mrb_value mrb_ensure(mrb_state *, mrb_func_t, mrb_value, mrb_func_t, mrb_value)
Ensure.
-
mrb_value mrb_rescue(mrb_state *, mrb_func_t, mrb_value, mrb_func_t, mrb_value)
Rescue.
-
mrb_value mrb_rescue_exceptions(mrb_state *, mrb_func_t, mrb_value, mrb_func_t, mrb_value, mrb_int, struct RClass *, classes)
Rescue exception.
Define Summary
- #define MRUBY_ERROR_H
- #define MRB_EXC_EXIT
error that should terminate execution
- #define MRB_EXC_EXIT_P
- #define MRB_EXC_EXIT_STATUS
retrieve status value from exc; need <mruby/variable.h> and <mruby/presym.h>
- #define MRB_EXC_CHECK_EXIT
exit with SystemExit status
- #define mrb_exc_ptr
- #define mrb_exc_new_lit
- #define MRB_USE_RBREAK_VALUE_UNION
- #define mrb_break_value_get
- #define mrb_break_value_set
- #define RBREAK_VALUE_TT_MASK
- #define MRB_ENSURE
Calls
funcviamrb_protect_error()and then always executes the user block exactly once. Even if a global jump (similar to a Ruby exception) occurs withinfunc, the block will be executed, and after the block's completion, the global jump will be re-thrown.By checking
mrb->exc != NULLwithin the block, you can determine if a global jump occurred infunc.If you want to suppress the global jump and continue processing, use
mrb_clear_error(mrb); break;.mrb: The mruby state referenceresult_var: Pre-defined mrb_value type variable (to receivefunc's return value)func: Function to call (compatible withmrb_protect_error_func)data: User data to pass tofunc
Example:
mrb_value result; MRB_ENSURE(mrb, result, body_func, userdata) { // This block is always executed (equivalent to Ruby's ensure) if (mrb->exc) { // Post-processing when an exception occurs } // To ignore the global jump, use `mrb_clear_error(mrb); break;` here }
Function Details
mrb_noreturn mrb_sys_fail(mrb_state * mrb, const char * mesg)
mrb_value mrb_exc_new_str(mrb_state * mrb, struct RClass* c, mrb_value str)
mrb_noreturn mrb_no_method_error(mrb_state * mrb, mrb_sym id, mrb_value args, const char * fmt, ... )
void mrb_clear_error(mrb_state * mrb)
clear error status in the mrb_state structure
mrb_bool mrb_check_error(mrb_state * mrb)
returns TRUE if error in the previous call; internally calls mrb_clear_error()
mrb_value mrb_protect_error(mrb_state * mrb, mrb_protect_error_func * body, void * userdata, mrb_bool * error)
mrb_value mrb_protect(mrb_state * mrb, mrb_func_t body, mrb_value data, mrb_bool * state)
Protect (takes mrb_value for body argument)
Implemented in the mruby-error mrbgem
mrb_value mrb_ensure(mrb_state * mrb, mrb_func_t body, mrb_value b_data, mrb_func_t ensure, mrb_value e_data)
Ensure
Implemented in the mruby-error mrbgem
mrb_value mrb_rescue(mrb_state * mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data)
Rescue
Implemented in the mruby-error mrbgem
mrb_value mrb_rescue_exceptions(mrb_state * mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data, mrb_int len, struct RClass * , classes )
Rescue exception
Implemented in the mruby-error mrbgem