mrb_protect() to return the exception raised (with the state of true)

parent 1085167f
......@@ -17,6 +17,7 @@ mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state)
mrb->jmp = prev_jmp;
} MRB_CATCH(&c_jmp) {
mrb->jmp = prev_jmp;
result = mrb_obj_value(mrb->exc);
mrb->exc = NULL;
if (state) { *state = TRUE; }
} MRB_END_EXC(&c_jmp);
......
assert 'mrb_protect' do
# no failure in protect returns [result, false]
assert_equal ['test', false] do
ExceptionTest.mrb_protect { 'test' }
end
assert_equal [nil, true] do
ExceptionTest.mrb_protect { raise 'test' }
end
# failure in protect returns [exception, true]
result = ExceptionTest.mrb_protect { raise 'test' }
assert_kind_of RuntimeError, result[0]
assert_true result[1]
end
assert 'mrb_ensure' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment