From: Ara.T.Howard@... Date: 2005-05-14T06:35:29+09:00 Subject: Re: Customing the Exception class On Sat, 14 May 2005, Daniel Berger wrote: > Hi all, > > I have a program where I want to send all errors to a file. So, I did this: > > class Exception > alias :old_init :initialize > def initialize(arg) > old_init(arg) > File.open("log.txt","a+"){ |fh| fh.puts("Error: #{arg}") } > end > end > > This works for most errors, but it doesn't seem to work when the error > is a SystemCallError. > > For example, this writes to the log as expected: > > print "Some crazy division: " > p 1/0 > > But this does not: > > File.open("non-existant file") > > The latter raises an Errno::ENOENT. > > Why, if SystemCallError is a subclass of Exception, does my approach not > work? How do I make this work as expected? maybe new? harp:~ > cat a.rb class Exception class << self alias ____new new def new(*a, &b) ret = ____new(*a, &b) STDERR.puts "new: <#{ a.inspect }>" ret end end alias ____init initialize def initialize(*a, &b) ret = ____init(*a, &b) STDERR.puts "initialize: <#{ a.inspect }>" ret end end SystemCallError::new 42 harp:~ > ruby a.rb new: <[42]> not sure why... -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================