所以我有经典的Ruby异常处理:
begin
# do work here
rescue SafeShutdown => e
# prevent loss of data and safely shutdown
rescue SystemExit => e
# print #{e} and continue
else
# how can I get #{e} here to get error message
# so I can behave like in previous rescue
#
# print #{e} and continue
end
我的问题是如何获取“e”以在记录器的其他部分打印出来。
最佳答案
在begin rescue
块中,仅当不发生异常(即未引发任何错误)时才调用else
。尝试这个:
begin
# do work here
rescue SafeShutdown => e
# print e
rescue SystemExit => e
# print e
else
# this will only run when no exceptions are thrown
ensure
# this will always run
end
关于ruby - else block 中的Ruby异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295926/