RosettaCodeData/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Ruby/exceptions-catch-an-exception-thrown-in-a-nested-call.rb
2015-11-18 06:14:39 +00:00

23 lines
256 B
Ruby

def foo
2.times do |i|
begin
bar(i)
rescue U0
$stderr.puts "captured exception U0"
end
end
end
def bar(i)
baz(i)
end
def baz(i)
raise i == 0 ? U0 : U1
end
class U0 < StandardError; end
class U1 < StandardError; end
foo