[英]Unable to rescue from “Lost connection to MySQL server” error
I have a block like so: 我有一个像这样的块:
begin
# some SQL request
rescue Mysql::Error => e
logputs "Mysql::Error occurred, retrying in 10s: #{e.message}"
sleep 10
retry
end
But when a "Lost connection to MySQL server" error occurred, this block was not able to catch it and retry (the MySQL server was restarted). 但是,当发生“与MySQL服务器的连接断开”错误时,该块无法捕获并重试(MySQL服务器已重新启动)。 Any idea how I can properly catch this exception? 知道如何正确捕获此异常吗?
Thanks! 谢谢!
From your comment it looks like what's happening is that a Mysql::Error exception is being thrown, but then caught by ActiveRecord which then throws an ActiveRecord::StatementInvalid exception (which isn't very helpful behaviour in this case!). 从您的评论看来,正在发生的事情是抛出了Mysql :: Error异常,但随后被ActiveRecord捕获,该异常随后引发了ActiveRecord :: StatementInvalid异常(在这种情况下,这不是很有用!)。
I'd say change your rescue to catch the AR::StatementInvalid exception and see what that does for you. 我想说说改变您的营救以捕获AR :: StatementInvalid异常,然后看看这对您有什么帮助。
Are you sure you are rescuing the correct type of exception? 您确定要挽救正确的异常类型吗?
Try using the following code: 尝试使用以下代码:
rescue StandardError => e
puts e
That should output any exception that is raised and more importantly you will be able to see the specific type. 那应该输出任何引发的异常,更重要的是,您将能够看到特定的类型。 Then you can adjust your rescue statement to be more specific. 然后,您可以调整您的救援声明,使其更加具体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.