From: Morton Goldberg Date: 2007-12-07T16:04:13+09:00 Subject: Re: Custom error handling question On Dec 6, 2007, at 6:04 PM, Anton Aylward wrote: > Some enlightenment. > > Firstly, the CustomError.new goes in the block of code that is yeilded > to, not in the wrapper. > > Secondly, even though I've found examples in the ruby libraray and > rails > of handlers beign extended and having methods of their own, I cna;'t > get it o work. > > For example, in actionpack/lib/action_view/base.rb > there is > > begin > render_template(template_extension, template_source, > template_file_name, local_assigns) > rescue Exception => e > if TemplateError === e > e.sub_template_of(template_file_name) > .... > > but when I try > > rescue CustomError => e > puts "Caught #{e.message.to_s}" > e.handle("#{e.message.to_s}", > "#{e.setup2.to_s}", "#{e.string3.to_s}") Is the 'puts "Caught #{e.message.to_s}"' being called? Do you see output from it? If the answer is NO, then my guess is that the statement in your code which raises a CustomError is not being called. > the handle method doesn't get invoked. I don't get an error message > about it either. > > I have, of course > > class CustomError < StandardError > > attr_accessor :setup1, :setup2, :setup3 > > def initialize(setup1, setup2, setup3) > @setup1 = setup1 > @setup2 = setup2 > @setup3 = setup3 > puts "Custom Error handler registered with #{@setup1.to_s}, > #{@setup2.to_s}, > #{setup3.to_s}" > end > > def handle( handle1, handle2, handle3) > puts "Custom error handler handled" > puts "\tsetup1 = #{@setup1}" > puts "\tsetup2 = #{@setup2}" > puts "\tsetup3 = #{@setup3}" > puts "\thandle1 = #{handle1}" > puts "\thandle2 = #{handle2}" > puts "\thandle3 = #{handle3}" > end > > end Regards, Morton