Forum: Ruby recue-raise vs catch-throw

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
41918fc34e4c3a365eabbd04ba9b551d?d=identicon&s=25 Vin Raja (vineetraja)
on 2007-07-12 11:32
Dear All

I wonder if anyone could better explain me the difference between
 rescue-raise and catch-throw paradigms

Thanks in Advance
Raja
Ee469623eb1b8e6e35d192822b9c4aa2?d=identicon&s=25 Florian Aßmann (Guest)
on 2007-07-12 11:43
(Received via mailing list)
Hi Vin Raja,
> I wonder if anyone could better explain me the difference between
>  rescue-raise and catch-throw paradigms
imho, with rescue you catch exceptions and with catch and throw
(opposite of continuations :) you skip the rest of a catch block with an
optional return value...

see http://whytheluckystiff.net/ruby/pickaxe/html/tut_...
for a more detailed explanation...

Regards
Florian
C06869c119472a139eb163b72040b0db?d=identicon&s=25 Bertram Scharpf (Guest)
on 2007-07-12 11:54
(Received via mailing list)
Hi,

Am Donnerstag, 12. Jul 2007, 18:32:49 +0900 schrieb Vin Raja:
> I wonder if anyone could better explain me the difference between
>  rescue-raise and catch-throw paradigms

I never felt no need to use catch-throw anywhere.
Maybe there is some special case I did not get in touch up
to now.

Bertram
41918fc34e4c3a365eabbd04ba9b551d?d=identicon&s=25 Vin Raja (vineetraja)
on 2007-07-12 12:26
>Florian
>see http://whytheluckystiff.net/ruby/pickaxe/html/tut_...
 Thanks


>Bertram Scharpf wrote:
> I never felt no need to use catch-throw anywhere.
Even I do wonder


---
Raja
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-07-12 13:12
(Received via mailing list)
2007/7/12, Vin Raja <vineetraja@gmail.com>:
>
> >Florian
> >see http://whytheluckystiff.net/ruby/pickaxe/html/tut_...
>  Thanks
>
>
> >Bertram Scharpf wrote:
> > I never felt no need to use catch-throw anywhere.
> Even I do wonder

raise / rescue is for error handling. catch / throw is for control
flow. catch / flow is especially useful if you have multiple exits for
a piece of code.  Although I have to say I rarely felt the need for
this. Basically it's the same as a method with multiple "return"s only
you do not leave the current scope.

Kind regards

robert
Bd4166a8d561763cd47294e6265d8bca?d=identicon&s=25 Mariusz Pękala (Guest)
on 2007-07-12 13:47
(Received via mailing list)
On 2007-07-12 18:32:49 +0900 (Thu, Jul), Vin Raja wrote:
> Dear All
>
> I wonder if anyone could better explain me the difference between
>  rescue-raise and catch-throw paradigms
>
> Thanks in Advance
> Raja

With raise you operate on descendants of Exception class.
With throw you can use any object.

I suppose this is the main difference.

Raise should be used for errors and similiar things, while throw just
for standard operations. It would be very confusing for the reader of
the code if raise would be used to pass data, and not for being the
signal that some dangerous/unusual condition may be handled here.
I guess.

Of course, I may be wrong ;-)
Bd4166a8d561763cd47294e6265d8bca?d=identicon&s=25 Mariusz Pękala (Guest)
on 2007-07-12 13:50
(Received via mailing list)
On 2007-07-12 19:26:11 +0900 (Thu, Jul), Vin Raja wrote:
> >Bertram Scharpf wrote:
> > I never felt no need to use catch-throw anywhere.
> Even I do wonder
>

Some deep recursive search comes to mind..
41918fc34e4c3a365eabbd04ba9b551d?d=identicon&s=25 Vin Raja (vineetraja)
on 2007-07-12 14:42
Mariusz Pękala wrote:
> Some deep recursive search comes to mind..

and that smells of a goto usecase !

or perhaps even I could be wrong :)
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-07-12 15:25
(Received via mailing list)
2007/7/12, Vin Raja <vineetraja@gmail.com>:
> Mariusz Pêkala wrote:
> > Some deep recursive search comes to mind..
>
> and that smells of a goto usecase !

Oh no! He used the g-word!! Decontaminate the mailing list!

;-)

robert
This topic is locked and can not be replied to.