if have function foo_1
calls foo_2
, , foo_2
can raise exception want handle in foo_1
. how can that?
i want write this, have deal 1 begin
/rescue
block:
def foo_1 begin foo_2 rescue someexception # stuff end end def foo_2 # stuff can throw someexception end
how can pass exception foo_2
?
if stack frame doesn't thrown exception, automatically propagate down next stack frame, until it's either handled or reaches bottom of stack (at point ruby interpreter handles printing out , program terminating). don't have enable behavior.
class someexception < standarderror; end def foo_1 begin foo_2 rescue someexception => e "rescued #{e.message} in foo_1" end end def foo_2 foo_3 end def foo_3 raise someexception.new("kaboom!") end # > foo_1 # => "rescued kaboom! in foo_1"
Comments
Post a Comment