我的应用程序(Ruby 1.9.2)可能会引发不同的异常,包括网络连接断开。我使用rescue Exception => e
捕获异常,然后使用case/when
以不同的方式处理它们,但有几个错误直接跳过了我的条件,进入了else
。
rescue Exception => e
p e.class
case e.class
when Errno::ECONNRESET
p 1
when Errno::ECONNRESET,Errno::ECONNABORTED,Errno::ETIMEDOUT
p 2
else
p 3
end
end
输出:
Errno::ECONNRESET
3