From: Paul Rogers Date: 2007-04-24T12:05:04+09:00 Subject: Re: exception and $! On Apr 23, 8:40 pm, james.d.mast...@gmail.com wrote: > On Apr 23, 6:55 pm, Paul Rogers wrote: > > > the pickaxe tells me that the last exception is available in $!, but > > c:\>irb > > irb(main):001:0> raise "Its all bad!" > > RuntimeError: Its all bad! > > from (irb):1 > > irb(main):002:0> puts $! > > nil > > You may need to check for $! within the context of a begin/rescue/end > block; this works: > > begin > raise "Its all bad!" > rescue > puts "rescuing... #{$!}" > end > > BTW, I'd recommend using the following instead of $! as $! is Perl- > esque (i.e. esoteric): > > begin > raise "Its all bad!" > rescue => error > puts "rescuing... #{error}" > # or even better use error.backtrace for backtrace information > end 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 #{$!}" Paul