Begin Rescue not catching error
我正在使用一些封装在begin-rescue块中的Ruby代码,但不知何故它仍然会崩溃。
代码块如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Retrieve messages from server def get_messages @connection.select('INBOX') @connection.uid_search(['ALL']).each do |uid| msg = @connection.uid_fetch(uid,'RFC822').first.attr['RFC822'] begin process_message(msg) add_to_processed_folder(uid) if @processed_folder rescue handle_bogus_message(msg) end # Mark message as deleted @connection.uid_store(uid,"+FLAGS", [:Seen, :Deleted]) end end |
考虑到这段代码,我假设如果process-message或add-to-processed文件夹无法执行,那么rescue将启动并调用handle-bogus-message。也就是说,我在生产环境中运行此代码,有时当我"收到"电子邮件消息(从rake任务运行)时,它会因语法错误而终止。
要查看错误消息,请访问http://pastie.org/1028479,它所指的进程消息与上面的进程消息不同。有什么理由不让救援队抓住这个例外吗?
没有参数的
为了挽救所有的例外情况,您可以使用
Rescuing Interrupt prevents the user from using CTRLC to exit the program.
Rescuing SignalException prevents the program from responding correctly to signals. It will be unkillable except by kill -9.
没有任何参数的