Ruby Exceptions 中直接引发的消息和从 evals 中引发的消息之间似乎存在奇怪的差异。例如,下面的代码:
def foo
raise "Help!"
end
puts "\nRescue foo"
begin
foo
rescue RuntimeError => e
puts e.message
end
puts "\nRescue eval 'foo'"
begin
eval "foo"
rescue RuntimeError => e
puts e.message
end
产生以下输出:
Rescue foo
Help!
Rescue eval 'foo'
./temp.rb:2:in `foo': Help!
没有使用正则表达式将其分出,在第二种情况下,有什么方法可以在没有上下文的情况下引发异常?