summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-error
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-07-15 14:45:32 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-07-15 14:47:15 +0900
commit207577f0af72874d9d643f2c46b881a9159d42d7 (patch)
tree83de6a20178bc3fb35dfc203731d58aa5559d5a3 /mrbgems/mruby-error
parent1085167fefe010be8e2d39e2adb31134a5512b15 (diff)
downloadmruby-207577f0af72874d9d643f2c46b881a9159d42d7.tar.gz
mruby-207577f0af72874d9d643f2c46b881a9159d42d7.zip
mrb_protect() to return the exception raised (with the state of true)
Diffstat (limited to 'mrbgems/mruby-error')
-rw-r--r--mrbgems/mruby-error/src/exception.c1
-rw-r--r--mrbgems/mruby-error/test/exception.rb8
2 files changed, 6 insertions, 3 deletions
diff --git a/mrbgems/mruby-error/src/exception.c b/mrbgems/mruby-error/src/exception.c
index 9d77c6adf..911fde0be 100644
--- a/mrbgems/mruby-error/src/exception.c
+++ b/mrbgems/mruby-error/src/exception.c
@@ -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);
diff --git a/mrbgems/mruby-error/test/exception.rb b/mrbgems/mruby-error/test/exception.rb
index b5ea719a2..0bbc2a0e7 100644
--- a/mrbgems/mruby-error/test/exception.rb
+++ b/mrbgems/mruby-error/test/exception.rb
@@ -1,10 +1,12 @@
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