[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Error handling
- From: Reuben Thomas <rrt@...>
- Date: Sun, 6 May 2001 12:27:04 +0100 (BST)
> That's one part of it. To be really effective, exceptions need to be
> "structured", i.e. the ability to derive similar - but special-case -
> exceptions, as Python and C++ support (and Tcl does not). The point is
> that you can as library designer create special kinds of, say, an IO
> expection with extra details or some specific meaning, whereas the
> library user just decides to catch all IO exceptions and treat them in
> the same generic manner. Both Python and C++ support this with (base)
> exception classes, and derived exception classes.
This sounds sensible, and in Lua it can be logically very lightweight,
because of dynamic typing: you could think of throw as just being a special
function that passes its arguments to the innermost (dynamically) enclosing
catch. "catch" can behave rather like "function", thus, assuming a Java-like
try-catch-finally construct:
try <block>
catch (x, y, z) <block>
[finally <block>] end
Here, the catch clause binds x, y, z just like in a function. Then it's up
to the programmer how to differentiate between exception types: in an
object-oriented paradigm, one would probably want to make catch always take
just a single argument, a table (object).
> If Lua is given more exception-handling capabilities, I would hope that
> the above issue is addressed. Raw "one-dimensional" exceptions can be
> extremely awkward in large applications. Python appears to strike a good
> balance between the width and depth of the exception hierarchy.
In Lua, the chosen method should, as ever, be a minimal extension, and not
enforce a particular style. The above proposal has a familiar syntax, and no
extra semantics aside from those for try, throw, catch and finally.
--
http://sc3d.org/rrt/ | certain, a. insufficiently analysed