Created
May 19, 2012 14:35
-
-
Save caike/2731045 to your computer and use it in GitHub Desktop.
nested begin;rescue;end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
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
Thanks for this. Always read nested begin rescue blocks weren't allowed in Ruby!