【发布时间】:2016-08-13 09:14:28
【问题描述】:
我需要在特殊情况下捕获 NameError。但我不想捕获 NameError 的所有子类。有没有办法做到这一点?
# This shall be catched
begin
String::NotExistend.new
rescue NameError
puts 'Will do something with this error'
end
# This shall not be catched
begin
# Will raise a NoMethodError but I don't want this Error to be catched
String.myattribute = 'value'
rescue NameError
puts 'Should never be called'
end
【问题讨论】:
标签: ruby nameerror nomethoderror rescue