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 ?
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jul-01 22:15 UTC
Re: handling my custom exceptions , is that right ?
On Jul 1, 10:57 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Jul 1, 10:57 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org>
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.