ITeye博客

Ruby 1.9概要(5) 异常

dennis_zane · 2008-10-03 13:26 · ruby & rails · Ruby · thread · Markdown

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)

2、SystemStackError现在继承Exception类,而非原来的StandardError :
1.8 

SystemStackError  <  StandardError   #  => true

1.9

SystemStackError  <  StandardError  #  => nil
   SystemStackError  <  Exception       # => true

3、移除了Exception#to_str方法 :

begin
    raise   " foo "
rescue
   $!.to_str
end

# => undefind method "to_str" for #<RuntimeError:foo>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。