2016-12-06 73 views
1

我有一个过程,是一个beginrescue循环中,看起来像这样:是否有可能开始..救援不捕捉异常?

begin 
    # do some stuff 
rescue Exception => e 
    Rails.logger.info "#{e.response.message}" 
end 

是否有可能在这抓不住一个例外?出于某种原因,我的过程正在运行,不会抛出错误,但随机不工作。

+0

您是否在生产环境?因为你不应该在那里看到信息记录。 – Ursus

+0

如果您营救“例外”,任何事情都可能发生。你应该赶上'StandardError' –

+2

_“不工作”_比较模糊,你能更具体吗? – Stefan

回答

0

也许你可以临时评论救援块:

#begin 
    ... 
#rescue Exception => e 
#Rails.logger.info "#{e.response.message}" 

,或者你可以提高救援提出这个异常:

begin 
    do some stuff 
rescue Exception => e 
    Rails.logger.info "#{e.response.message}" 
    raise e 
end 
1

只需使用:

# do some stuff 

没有任何开始/救援块,并看看哪个错误出来。假设它是NoMethodError。也许你在你的一些代码中有一个错字,比如"abc".spilt。 纠正它。再试一次,也许你会得到Errno::ECONNRESET

尝试:

begin 
    # do some stuff 
rescue Errno::ECONNRESET => e 
    Rails.logger.info "#{e.message}" 
end 

冲洗和重复,而是从头开始。 rescue Exception只是too much