Skip to content

Instantly share code, notes, and snippets.

@caike
Created May 19, 2012 14:35
Show Gist options
  • Select an option

  • Save caike/2731045 to your computer and use it in GitHub Desktop.

Select an option

Save caike/2731045 to your computer and use it in GitHub Desktop.
nested begin;rescue;end
class FooError < StandardError
end
begin
p "about to raise Foo.."
raise FooError.new
rescue FooError
p 'rescues from Foo'
begin
p 'about to raise Meh..'
raise 'Meh'
rescue
p "rescues from Meh"
end
end
#"about to raise Foo.."
#"rescues from Foo"
#"about to raise Meh.."
#"rescues from Meh"
@rapcal
Copy link

rapcal commented Sep 10, 2013

Thanks for this. Always read nested begin rescue blocks weren't allowed in Ruby!

@Joshfindit
Copy link

A handy note as well: errors are not 'bubbled up' through the begin/rescue chain.
In order to have an exception bubble up, use raise $!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment