Rails Resuce,在Switch Rescue中提供信息
我有以下内容:
class MailingJob < Struct.new(:mailing_id)
class MissingInfo < ArgumentError; end
def perform
....
begin
......
raise MissingInfo, "Not found", message_all, @message_from if @message_reply.length == 0
......
rescue MissingInfo => reason, message_all, message_from
UserMailer.delay.incoming_mails_error_notification(reason, message_all, message_from)
end
end
我在这里遇到的问题是,在我的resuce中,我需要访问begin块中的几个变量,所以当我调用RAISE时,我正试图传递它们。这似乎不起作用。而且,这些变量在许多加注中都是一致的,因此它实际上填满了页面。
有没有办法让这些变量在resuce中可访问,而不必在加注中定义它们?
如果没有,我如何使用加注来将它们传递给救援人员?以上错误包括:
SyntaxError (/Users/xxxxx/Sites/xxxxxxx/lib/mailing_job.rb:117: syntax error, unexpected ',', expecting kTHEN or ':' or 'n' or ';'
rescue MissingInfo => reason, message_all, message_from
^
谢谢!
没有找到相关结果
已邀请:
1 个回复
钨蜡唤喉晤
关键字只捕获错误对象。您需要在异常对象中捕获这些值:
但这是滥用错误处理。通常最好使用begin和raise来表示真正的错误,这是你不期望的错误。 MissingInfo听起来像处理用户输入。您可以预期用户输入会丢失数据。做正常的检查。试着想一想你真正想要传达的行为。