The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
$SIG{"RUBY"}

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
$SIG{"RUBY"} Posted: Sep 20, 2005 9:32 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: $SIG{"RUBY"}
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
One of the things I miss from Perl when I'm using Ruby are the global $SIG{WARN} and $SIG{DIE} handlers. For reports & other various things, my typical idiom was this (using a bit of pseudo code):
# Avoid in combination with eval
$SIG{DIE}= sub {
   # Log error
   # Send out email to interested parties
}

This can be done in Ruby by overriding the Exception class. Easy enough:
# Totally untested
class Exception
   @@proc_handler = nil
   def initialize
      # old initialize
      # @@proc_handler.call if @@proc_handler
   end

   def self.proc_handler=(proc_obj)
      @@proc_handler = proc_obj
   end

   def self.proc_handler
      @@proc_handler
   end 
end

But, this is a pain to have to do for every report generation script I have. I think I might wrap this in a simple, generic package that folks can use. Thus, your cod would look something like this:
Exception.proc_handler = lambda{
   # Log error
   # Send out email to interested parties
}

Then, whenver an exception occurs anywhere in your code it will call the proc you've assigned. At least, I think it will.

Read: $SIG{"RUBY"}

Topic: Date::Calc nightmare Previous Topic   Next Topic Topic: Cool game

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use