use*_*029 2 ruby exception-handling exception rescue
在Ruby中,是否有可能引发一个异常,它也会自动中止程序,忽略任何封闭的开始/救援块?
不幸的是,这些exit
答案都不起作用.exit
提升SystemExit
可以抓住.注意:
begin
exit
rescue SystemExit
end
puts "Still here!"
Run Code Online (Sandbox Code Playgroud)
正如@dominikh所说,你需要使用exit!
:
begin
exit!
rescue SystemExit
end
puts "Didn't make it here :("
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2300 次 |
最近记录: |