[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Cardinal-dev] Does Ruby require restartable exceptions?
From: |
Erik Bågfors |
Subject: |
Re: [Cardinal-dev] Does Ruby require restartable exceptions? |
Date: |
30 May 2002 20:28:15 +0200 |
On Thu, 2002-05-30 at 19:10, Dan Sugalski wrote:
> At 6:49 PM +0200 5/30/02, Erik Bågfors wrote:
> >On Thu, 2002-05-30 at 18:38, Dan Sugalski wrote:
> >> Here's a question. Does Ruby require that you be able to catch an
> >> exception then restart or resume from where the exception was thrown?
> >
> >AFAIK no,
> >
> >What you do in ruby is restart by hand.
>
> Cool. I was worried you could do something like:
>
> try {
> object.method_which_pitches_exception();
> } catch {
> resume;
> }
>
> and have the resume jump back into the object's method at the place
> where it threw the exception. Not having to do that makes life easier.
I've never seen that, but I'm not 100% sure about it.
Another thing you have in ruby is "throw" and "catch". They have
nothing to do with the try/catch/throw that you have in for example
java.
It works like this. (example from the pickaxe-book)
The following example uses a throw to terminate interaction with the
user if ``!'' is typed in response to any prompt.
def promptAndGet(prompt)
print prompt
res = readline.chomp
throw :quitRequested if res == "!"
return res
end
catch :quitRequested do
name = promptAndGet("Name: ")
age = promptAndGet("Age: ")
sex = promptAndGet("Sex: ")
# ..
# process information
end
What happens here is that when ruby encounters a throw it works it's way
up the call stack until it finds a catch-block with a matching symbol.
Then it unwinds the stack to that point ant terminates the block (do/end
here is a continuation-block I assume)...
So.. this is not really exceptions but it kindof behaves that way.
I have no idea how this will affect parrot or if it will in any way.
Perhaps this is already handleable.
/Erik
--
Erik Bågfors | address@hidden
Supporter of free software | GSM +46 733 279 273
fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32