rails 3 - Raising an exception? Using Begin, Rescue and Raising Expections
I'm getting the following error:
MailingJob failed with NameError: uninitialized constant MailingJob::MissingInfo - 2 failed attempts
My code:开发者_Python百科
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
This is my first time using begin/rescue, suggestions,help? Thanks
You are attempting to use an undefined constant. You must define the exception class:
class MissingInfo < StandardError; end
Secondly, I wouldn't rely on the logs to capture the errors. Instead, I would use a service such as Hoptoad for that.
精彩评论