rails 3 - 提出异常?使用开始,拯救和提高期望

时间:2010-12-12 20:37:58

标签: ruby-on-rails ruby

我收到以下错误:

MailingJob failed with NameError: uninitialized constant MailingJob::MissingInfo - 2 failed attempts

我的代码:

class MailingJob < Struct.new(:mailing_id)
  def perform
    begin
       @message_reply = ....
       raise MissingInfo, "Message reply not found" if @message_reply.length == 0
       .....
    rescue MissingInfo => detail
        Rails.logger.info "RESCUED - MissingInfo,RESCUED - MissingInfo, RESCUED - MissingInfo, RESCUED - MissingInfo, RESCUED - MissingInfo"
        Rails.logger.info detail
    end

  end

这是我第一次使用开始/救援,建议,帮助?感谢

1 个答案:

答案 0 :(得分:1)

您正在尝试使用未定义的常量。您必须定义异常类:

class MissingInfo < StandardError; end

其次,我不会依赖日志来捕获错误。相反,我会使用诸如Hoptoad之类的服务。