Ruby 1.9概要(5) 異常
1、異常的相等性,如果兩個異常的class、message和backtrace一樣,那麼認為這兩個異常是相等的,可以通過==判斷。
def method
raise 'foobar'
end
errors = []
2.times do
Thread.new do
begin
method
rescue => e
errors << e
end
end.join
end
puts errors[-2] == errors[-1] #=> true (1.9) false(1.8)
raise 'foobar'
end
errors = []
2.times do
Thread.new do
begin
method
rescue => e
errors << e
end
end.join
end
puts errors[-2] == errors[-1] #=> true (1.9) false(1.8)
2、SystemStackError現在繼承Exception類,而非原來的StandardError:
1.8
SystemStackError < StandardError # => true
1.9
SystemStackError < StandardError # => nil
SystemStackError < Exception #=> true
SystemStackError < Exception #=> true
3、移除了Exception#to_str方法:
begin
raise "foo"
rescue
$!.to_str
end
#=> undefind method "to_str" for #<RuntimeError:foo>
文章轉自莊周夢蝶 ,原文發布時間 2008-10-03 raise "foo"
rescue
$!.to_str
end
#=> undefind method "to_str" for #<RuntimeError:foo>
最後更新:2017-05-18 11:01:54