From: Robert Evans Date: 2007-04-25T01:04:07+09:00 Subject: Re: exception and $! If I understand what you are trying to do (refactor a bunch of exception handling code) then maybe overriding the #rescue method in general for your session so that it always print it's exception and stacktrace, would give you the information you want. Bob Evans http://www.junitfactory.com/ On Apr 24, 2007, at 7:50 AM, Paul Rogers wrote: > On Apr 23, 9:42 pm, james.d.mast...@gmail.com wrote: >> On Apr 23, 8:29 pm, Paul Rogers wrote: >> >>>>> Thanks, I actually wanted to see what the last exception was >>>>> out side >>>>> of a block, kind of like this >>>>> begin >>>>> raise "bad" >>>>> rescue => e >>>>> puts "#{e} was raised" >>>>> end >>>>> puts "Just to make sure, last exception was #{$!}" >> >> If you don't have your heart set on using $!, then just put the >> contents into a variable (code not tested): >> >> last_error = nil >> begin >> raise "bad" >> rescue => e >> last_error = e >> end >> >> puts "An error was encountered: #{e}" if e > > The reason I have to do this, and why $! was so attractive is that I > have many rescue blocks scattered throughout the code, which Im trying > to fix up, but I dont want to do them all at once, so just seeing the > last exception, was going to be helpful. I have another work around > that isnt as nice as $! appeared to be, but it does enough for what I > need > > Thanks for all your help > Paul > >