【发布时间】:2010-10-10 21:57:55
【问题描述】:
class Collector
class ContentNotFound < Exception
end
class DuplicateContent < Exception
end
end
begin
raise Collector::ContentNotFound.new
rescue
puts "catch"
end
当我运行脚本时,我没有收到“catch”消息,但我看到了错误:
lib/collector/exception.rb:10:in `<main>': Collector::ContentNotFound (Collector::ContentNotFound)
为什么?如何在没有在救援中键入它们的类的情况下捕获我的异常?
【问题讨论】:
-
您不需要
.new- 您只需拥有raise Collector::ContentNotFound。 ruby 魔法的所有部分。