Don't rescue Exception, rescue StandardError
Before
begin
foo
rescue Exception => e
logger.warn "Unable to foo, will ignore: #{e}"
end
Refactor
begin
foo
rescue => e
logger.warn "Unable to foo, will ignore: #{e}"
end
默认只能捕获 StandardError,图示说明了 ruby 的异常类型和关系。
See : http://rails-bestpractices.com/posts/702-don-t-rescue-exception-rescue-standarderror
http://stackoverflow.com/questions/10048173/why-is-it-bad-style-to-rescue-exception-e-in-ruby