[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Nuby: How do I find out what exception was thrown?

rpardee

9/28/2004 1:29:00 AM

Bingo--that's it I think. Thanks! It's working now.

That begin ... rescue... end syntax is reminiscient of
try...catch--that's how i'll remember it.

Thanks!

-Roy

Mark Hubbart <discord@mac.com> wrote in message news:<60C1F098-0F84-11D9-B8CF-000A95D2DFAE@mac.com>...
> On Sep 25, 2004, at 9:19 PM, Roy Pardee wrote:
>
> > 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?
>
>
>
> The rescue keyword can be used in two and a half different ways:
>
> 1. As a statement modifier:
> puts 0/0 rescue puts 23 # prints 23
>
> 2. In a begin...end block:
> begin
> puts 0/0
> rescue ZeroDivisionError => err
> puts 42
> end # prints 42
>
> 2.5. Within other certain supported code blocks:
> def foo(bar, baz)
> bar/baz
> rescue ZeroDivisionError
> 23
> rescue Exception
> 42
> end
>
> If it isn't used in one of these ways, it gives a parse error. I
> suspect that's what the problem is; you just need to enclose the
> error-causing part of the script in a begin...end block, with a rescue
> clause.
>
> cheers,
> Mark
>