From: rpardee@... (Roy Pardee) Date: 2004-09-26T13:19:26+09:00 Subject: Re: Nuby: How do I find out what exception was thrown? Thanks all for the responses. I think the exception is not Errno::EACCES tho. If I throw this at the end of my script: rescue Errno::EACCESS => exp puts "In rescue section" end Ruby comes back with: F:\>ruby KillOwnerLok.rb KillOwnerLok.rb:18: syntax error rescue Errno::EACCESS => exp ^ I must be doing something very wrong, b/c if I change that to: rescue StandardError puts "In rescue section" end Ruby says: F:\>ruby KillOwnerLok.rb KillOwnerLok.rb:18: syntax error rescue StandardError ^ Any further advice? Thanks! -Roy Tim Hunter wrote in message news:... > Roy Pardee wrote: > > > If I try to run this while the file in question is opened by another > > process I get this output: > > > > ------------------------------------------ > > F:\>ruby KillOwnerLok.rb > > \\blackula\Profiles\Laurel\Application Data\Qualcomm\Eudora\owner.lok > > found! > > KillOwnerLok.rb:9:in `delete': Permission denied - > > \\blackula\Profiles\Laurel\Ap > > plication Data\Qualcomm\Eudora\owner.lok (Errno::EACCES) > > from KillOwnerLok.rb:9 > > ------------------------------------------ > > > > I'd like to print my "Could not delete..." message in a rescue > > section, but I don't know how to translate the error message from the > > output into something 'rescuable'. How do I do that? > > Ruby's telling you: Errno::EACCES > > rescue Errno::EACCES => exp > puts "Caught an exception: #{exp.message}" > end > > But you probably want to catch other Errno's, too. You can catch them all by > rescuing StandardError. If you need to know exactly which exception was > thrown you can call `exp.class' in your rescue clause.