ssoroka (owner)

Revisions

gist: 157463 Download_button fork
public
Public Clone URL: git://gist.github.com/157463.git
Embed All Files: show embed
blowup.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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!