庄周梦蝶

生活、程序、未来
   :: 首页 ::  ::  :: 聚合  :: 管理

Ruby 1.9概要(5) 异常

Posted on 2008-10-03 13:26 dennis 阅读(537) 评论(0)  编辑  收藏 所属分类: 动态语言
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>



只有注册用户登录后才能发表评论。


网站导航: