I a using delayed_job, and I am raising an exception this way : config/initializers/custom_exceptions.rb class RemoteLockerException < StandardError; end class RemoteLockerDenied < StandardError; end lib/instruction_request_job.rb class InstructionRequestJob < Struct.new(:style, :request_id) def perform ....> connector = RemoteContainerServer::Connector.create!(remote_container) > raise Exceptions::RemoteLockerDenied , "RemoteLockerDenied" if connector.nil?....> requestId = connector.request_job(user, remote_container) > raise Exceptions::RemoteContainerException, "RemoteContainerException" if requestId.nil?... end there is a hook for any exception raised, to trap ALL the errors and do something according to the raised exception , i.e. : def error(job, exception) case exception when "RemoteContainerDenied" .. do something when "RemoteContainerException" .. do something else ...... end end I am new to ''exception raising'' ... so I initially thought I could trap the exception message : "RemoteLockerDenied" or "RemoteContainerException" as case parameter exception but it seems not working that way ... when raised , I get #<NameError: uninitialized constant InstructionRequestJob::Exceptions> which is the exception type, not the message ... I may be ( surely) totally wrong ..... how should I proceed ? -- 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.
On May 22, 4:36 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> I a using delayed_job, and I am raising an exception this way : > > config/initializers/custom_exceptions.rb > class RemoteLockerException < StandardError; end > class RemoteLockerDenied < StandardError; endThis should define just RemoteLockerDenied, not Exceptions::RemoteLockerDenied.> > there is a hook for any exception raised, to trap ALL the errors > and do something according to the raised exception , i.e. : > > def error(job, exception) > case exception > when "RemoteContainerDenied" > .. do something > when "RemoteContainerException" > .. do something else ...... > end > endYour whens should use the exception class, not the name, ie when RemoteLockerDenied instead of when ''RemoteLockerDenied'' Fred -- 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.
Thanks Fred I believe I can pass parameters to the Exception class for fine grain processing will read more about it .. any better link than Rials doc , On 22 mai, 19:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 22, 4:36 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > I a using delayed_job, and I am raising an exception this way : > > > config/initializers/custom_exceptions.rb > > class RemoteLockerException < StandardError; end > > class RemoteLockerDenied < StandardError; end > > This should define just RemoteLockerDenied, not > Exceptions::RemoteLockerDenied. > > > > > there is a hook for any exception raised, to trap ALL the errors > > and do something according to the raised exception , i.e. : > > > def error(job, exception) > > case exception > > when "RemoteContainerDenied" > > .. do something > > when "RemoteContainerException" > > .. do something else ...... > > end > > end > > Your whens should use the exception class, not the name, ie > > when RemoteLockerDenied instead of when ''RemoteLockerDenied'' > > Fred-- 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.
On May 23, 7:11 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> Thanks Fred > > I believe I can pass parameters to the Exception class for fine grain > processing > will read more about it .. any better link than Rials doc , >You probably want some pure ruby documentation - this isn''t rails specific at all. Your subclasses of StandardError can store as many extra bits of information about the error that occurred as you want - just override the initialize method to stash the information in an instance variable or something like that Fred> On 22 mai, 19:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On May 22, 4:36 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > I a using delayed_job, and I am raising an exception this way : > > > > config/initializers/custom_exceptions.rb > > > class RemoteLockerException < StandardError; end > > > class RemoteLockerDenied < StandardError; end > > > This should define just RemoteLockerDenied, not > > Exceptions::RemoteLockerDenied. > > > > there is a hook for any exception raised, to trap ALL the errors > > > and do something according to the raised exception , i.e. : > > > > def error(job, exception) > > > case exception > > > when "RemoteContainerDenied" > > > .. do something > > > when "RemoteContainerException" > > > .. do something else ...... > > > end > > > end > > > Your whens should use the exception class, not the name, ie > > > when RemoteLockerDenied instead of when ''RemoteLockerDenied'' > > > Fred-- 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.
got it .. and it''s running well , may be not the best coding , but it runs .... in my config/initializers/custom_exceptions.rb Module Exceptions class RemoteContainerDenied < StandardError def initialize(msg, remote_container_id, request_id , user_id) super(msg) @message = msg @request_id = request_id @remote_container_id = remote_container_id @user_id = user_id end def message; @message + "remote_container_id: #{@remote_container_id} , requestId: #{@request_id}"; end def remote_container_id; @remote_container_id; end def request_id; @request_id; end def user_id; @user_id; end end end raised with : raise(RemoteContainerDenied.new("Access denied", remote_container_id[:id], request[:id], user[:id] ) if response.nil? et voilà ... then I can trap these exceptions in delayed_job ( error hook) and act according to the exception : def error(job, exception) case exception when RemoteLockerDenied AdminMailer..... very awesome On 23 mai, 11:38, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 23, 7:11 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> Thanks Fred > > > I believe I can pass parameters to the Exception class for fine grain > > processing > > will read more about it .. any better link than Rials doc , > > You probably want some pure ruby documentation - this isn''t rails > specific at all. > Your subclasses of StandardError can store as many extra bits of > information about the error that occurred as you want - just override > the initialize method to stash the information in an instance variable > or something like that > > Fred > > > > > On 22 mai, 19:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On May 22, 4:36 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > > I a using delayed_job, and I am raising an exception this way : > > > > > config/initializers/custom_exceptions.rb > > > > class RemoteLockerException < StandardError; end > > > > class RemoteLockerDenied < StandardError; end > > > > This should define just RemoteLockerDenied, not > > > Exceptions::RemoteLockerDenied. > > > > > there is a hook for any exception raised, to trap ALL the errors > > > > and do something according to the raised exception , i.e. : > > > > > def error(job, exception) > > > > case exception > > > > when "RemoteContainerDenied" > > > > .. do something > > > > when "RemoteContainerException" > > > > .. do something else ...... > > > > end > > > > end > > > > Your whens should use the exception class, not the name, ie > > > > when RemoteLockerDenied instead of when ''RemoteLockerDenied'' > > > > Fred-- 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.
On May 23, 11:39 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> def remote_container_id; @remote_container_id; end > def request_id; @request_id; end > def user_id; @user_id; endby the way, if you were to write attr_reader :remote_container_id, :request_id, :user_id then that would write your reader methods for you Fred -- 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.
Hi Guys Trying to copy your code but not having any luck All I get is "wrong number of arguments (3 for 0..1)" in the initialize call back actually referring to the .new call in the raise Can''t see what I''m doing wrong. Any help greatly appreciated regards dukha module Exceptions class IncorrectArrayFormatInYamlFile < StandardError attr_accessible :line_number, :translation_file_id def initialize( msg, line_number, translation_file_id) super(msg) @line_number = line_number @translation_file_id =translation_file_id end def file_name return TranslationFile.find(@translation_file_id).english_translation_file_name end def message message = @message + "line number: #{@line_number}, file: #{file_name}." end end end msg = "This file is using incorrect array format. Change file format from \" - <array_element>\" to key: [element1,element2..]. This element is on line " + line_sequence.to_s + " in " + TranslationFile.find(translation_file_id).english_translation_file_name raise Exceptions::IncorrectArrayFormatInYamlFile.new msg, line_sequence, translation_file_id On May 23, 10:36 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 23, 11:39 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > def remote_container_id; @remote_container_id; end > > def request_id; @request_id; end > > def user_id; @user_id; end > > by the way, if you were to write > > attr_reader :remote_container_id, :request_id, :user_id then that > would write your reader methods for you > > Fred-- 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.