Skip to content

Instantly share code, notes, and snippets.

@ssoroka
Created July 28, 2009 15:46
Show Gist options
  • Save ssoroka/157463 to your computer and use it in GitHub Desktop.
Save ssoroka/157463 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def test1
begin
raise Exception.new("worked1")
rescue Exception => e
puts "caught exception1"
end
end
def test2
raise Exception.new("worked2")
rescue Exception => e
puts "caught exception2"
end
def test3
begin
raise Exception.new("worked3")
rescue
puts "caught exception3"
end
end
def test4
raise Exception.new("worked4")
rescue
puts "caught exception4"
end
test1
test2
test3
test4
############# Can anyone explain this output?!
# $ ruby blowup.rb
# caught exception1
# caught exception2
# blowup.rb:19:in `test3': worked3 (Exception)
# from blowup.rb:33
#
# Found the answer here: http://engineroom.mixx.com/2008/07/31/when-rescue-doesnt/
# rescue without params only catches StandardError, not Exception. Boo!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment