Ruby on Rails Saturday, July 2, 2011

solved ... not related to exception .. correctly passed and raised,
but rather related to a bad delayed_job struct definition

class InstructionRequestJob <
Struct.new(:param1, :param2, :param3, :error)

but I enqueued it w only 2 parameters :
Delayed::Job.enqueue InstructionRequestJob.new( param1, param2)

so got issue with the DJ :error catch...
writing : Delayed::Job.enqueue InstructionRequestJob.new( param1,
param2, params3) solved the issue :
def error(job, exception)
..
error_code = exception.error_code # or anything else stored in
the exception...
...
end
catching correctly the raised exception ...

thanks a lot

On Jul 2, 12:15 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:
> On Jul 1, 10:57 pm, Erwin <yves_duf...@mac.com> wrote:
>
>
>
> >  in my config/initializers  , I created the file custom_exceptions.rb
> > in which I put all my custom exceptions
> > ..
> > module Exceptions
> >  class MyLockerException < StandardError
> >     def initialize(msg, error_code , member_id  )
> >         super(msg)
> >         @message = msg
> >         @error_code = error_code
> >         @member_id = member_id
> >     end
>
> >     def message
> >       @message + ", member: #{@member_id}  , ERROR: #{@error_code}"
> >     end
> >     def error_code
> >       @error_code
> >     end
> >     def member_id
> >       @member_id
> >     end
> >   end
> > ...
>
> > I have a Delayed_job script , in which I raise the exceptions like
> > this :
> > ...
> >   raise Exceptions::MyLockerException.new("MyLockerException",
> > error_code, locker[:id],  member[:id], ) if analysis.nil?
> > ..
> > when the exception is raised , it's catch by the error method
>
> >     def error(job, exception)
> >       memberId = exception.member_id
>
> > but , I got an error  =>  member_id is not defined in exception ...
> > why ?   member_id is clearly defined in the class MyLockerException  ,
> > isn't it ?
>
> Are you sure the exception passed to the error method is the one you
> expected ?
>
> Fred
>
>
>
> > thanks for your feedback

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment