begin
#dosomething
rescue Exception => e
#halt the exception's progress
end
我希望能够使用Ctrl+C关闭它。
我想要写的代码是:
begin
#dosomething
rescue SignalException => e
raise e
rescue Exception => e
#halt the exception's progress
end
发布于 2018-03-21 15:34:58
如果可以打包整个程序,执行如下操作:
trap("SIGINT") { throw :ctrl_c }
catch :ctrl_c do
begin
sleep(10)
rescue Exception
puts "Not printed"
end
end
这基本上是CtrlC使用CATCH/HOP而不是异常处理,所以除非现有代码已经有了CATCH:Ctrl_C在里面。
https://stackoverflow.com/questions/-100007705
复制相似问题