def explode
raise "bam!" if rand(10) == 0
end
def risky
10.times do
explode
end
begin
puts "xxx"
rescue Exception => f (本来是期望这里能捕捉到的)
puts f.class
end
"hello"
end
def defuse
puts risky
end
defuse
但实际执行时打出了整个 backtrace,说明没捕捉到
irb(main):024:0> defuse
RuntimeError: bam!
from (irb):2:in `explode'
from (irb):8:in `block in risky'
from (irb):7:in `times'
from (irb):7:in `risky'
from (irb):21:in `defuse'
from (irb):24
from /home/bob/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
irb(main):025:0>