Re: Stylistic question on control transfer (return vs. throw)



Mikalai wrote:
Kenny Tilton wrote:

You found /some/ similarities. You missed some differences.

If I am looking at a throw, I have no idea where it will land, including
a backtrace. If I am looking at (return-from X...) I know the function
or block X will simply exit with the value specified.

Then we have dynamic vs lexical, the runtime cost thereof....


That is it.

Stylistically, one only uses throw in the way one would signal an error.
ie, You want control to jump from here-and-now to whoever-cares-if-anyone.


OK. Where is it clearer to use throw not an error?

Here is one situation. I have used THROW in order to define a protocol
for bailing out of self-contained body of code after all internal error
handling has failed. So the situation was no longer an error, just the
ultimate escape mechanism. The THROW is what a catch-all error hander
would do if it could not find a suitable restart.

The outer wrapper would just exit to the operating system with a
termination status. But I did not want to scatter these exit calls
throughout the code, because unwinding would not take place.

INVOKE-RESTART could have been used also, but THROW and CATCH quite
simply have simpler syntactic sugar.

In Lisp, dynamic non-local returns aren't used for error situations:
conditions are. A dynamic return is done as the last step, when error
handling has been settled.

Normally, this is done with restarts.

A simple catch can be used as a restart when you don't need the ability
of being able to determine whether a restart is available; it's trusted
to just be there.

With restarts, you can enumerate available restarts, determine whether
a particular restart is available, making restarts invisible based on
logical conditions and such.

There are probably overheads in restarts compared to catches for all
these added capabilities.

.



Relevant Pages

  • Re: lsass Boot Error
    ... I press F10 to save and ... When I do that the computer shuts down and restarts. ... restarts I check the F2 setup again that CD-ROM is where I selected it. ... > but you will have to Save when you exit in order for the change to stick. ...
    (microsoft.public.windowsxp.general)
  • incompatible exit values between python 2.4 and 2.5
    ... I have a small C program that restarts a python based server ... application if the exit value of the ... With python 2.4, if pythonscript.py could not be found, the exit value ...
    (comp.lang.python)