On 10/7/05, Ara.T.Howard <Ara.T.Howard / noaa.gov> wrote: > harp:~ > cat a.rb > class Exception > class << self > def __initialize__hooks__ > @@__initialize__hooks__ ||= [] > end > end > > alias_method '__initialize__', 'initialize' > > def initialize *a, &b > klass = self.class > if klass.__initialize__hooks__ > klass.__initialize__hooks__.each do |hook| > hook.call self, a, b > end > end > __initialize__ *a, &b > end > end > > > def exception_intercept *handlers > handlers.flatten! > handlers.compact! > n = handlers.size > begin > n.times{ Exception::__initialize__hooks__.push handlers.shift} > yield > ensure > n.times{ Exception::__initialize__hooks__.pop } > end > end > > email = lambda{|exp, args, block| p ['mail', exp, args, block]} > another = lambda{|exp, args, block| p ['another', exp, args, block]} > > exception_intercept(email, another) do > raise ArgumentError, 'forty-two' > end > > harp:~ > ruby a.rb > ["mail", #<ArgumentError: ArgumentError>, ["forty-two"], nil] > ["another", #<ArgumentError: ArgumentError>, ["forty-two"], nil] > a.rb:38: forty-two (ArgumentError) > from a.rb:37:in `exception_intercept' > from a.rb:37 Not that this code isn't a fine example of some of the things you can do, but I was thinking more along the lines of this: #! ruby begin require ARGV.shift rescue # send it to yourself end If we called this script 'cronmail', then you could put 'cronmail real_script.rb [args 'n' stuff]' in the tab for any program for which you wanted to mail those pesky errors. -- Rob (Simple-minded Solutions, Inc.)