From: Martin Hansen Date: 2010-08-05T19:06:05+09:00 Subject: Abstracting exception handling Hello, I am interested in abstracting exception handling so it can be included to any script from some external file. First, I want to setup signal handling, and last I want to deal with exceptions. Now, in this little test of mine something is bad, since the exception is not caught. I suspect something is going out of scope and lost? Martin #!/usr/bin/env ruby def do_at_begin exit_status = "OK" # Install signal handlers %w( INT TERM QUIT ).each do |signal| Signal.trap(signal) do exit_status = signal exit end end exit_status end def do_at_exit(exit_status="OK-default") begin rescue Exception => exception $stderr.puts "Exception caught!" $stderr.puts exit_status $stderr.puts exception.backtrace ensure puts "DEBUG EXIT STATUS: #{exit_status}" end end exit_status = do_at_begin raise END { do_at_exit(exit_status) } -- Posted via http://www.ruby-forum.com/.