From: jackster the jackle Date: 2008-10-21T00:39:20+09:00 Subject: Re: Error Exception if script doesn't run That really helps clear things up..thanks. I am almost there but have been struggling to get my e.message into my sendmail statement. This code works perfectly but does not contain the value of e in my email: rescue Exception => e #puts e.message ->prints out correctly #puts e.backtrace.first -> prints out correctly if e `echo "Subject:Error Message\n" | /usr/sbin/sendmail -f my_server\@server.com john.smith\@email.com` end end When I try to add the value of e into my email message, it won't send: `echo "Subject:Error Message\n #{e.message}" | /usr/sbin/sendmail -f my_server\@server.com john.smith\@email.com` I think it has something to do with the ` and " characters but I have tried every possible combination and I can't figure out why doesn't work? thanks jack Brian Candler wrote: > jackster the jackle wrote: >> I would like to be able to add the line number of the file into the >> error message with the file name ($0) but when I try other global >> variables such as $@ or $. I don't get the line number of the script >> that failed? > > Use __FILE__ and __LINE__ > > You probably don't want $0, although it will work if all your code is in > one file; if your script was called foo.rb but it did "require 'bar'" > and the error was in bar.rb, then __FILE__ would be bar.rb but $0 would > be foo.rb > > But in any case, you don't need this because > > raise "Hell" > > gives you a stack backtrace anyway, the first line of which is the line > where the raise occurred. > > begin > raise "Hell" > rescue Exception => e > puts "Error: #{e.message} at #{e.backtrace.first}" > end -- Posted via http://www.ruby-forum.com/.