Re: Benefits of Dynamic Typing
- From: Marcin 'Qrczak' Kowalczyk <qrczak@xxxxxxxxxx>
- Date: Sat, 01 Oct 2005 22:16:38 +0200
Joachim Durchholz <jo@xxxxxxxxxxxxx> writes:
> The best I can do is to compare with projects I have been involved
> with - and it never occurred that there was a *need* to handle errors
> differently.
Perhaps this was accidental: I anticipated more errors to be fatal
when I was designing that, and it turned out that in most cases it's
easy to return some dummy value (or a designated value for an error)
and continue.
I just listed all cases where my code did catch specific exceptions
(i.e. excluding generic constructs which catch exceptions around some
body but do the same thing for any exception). Even if some of them
could be avoided by structuring the program differently, I prefer to
be less constrained and have more options available.
> You need an exception trace, i.e. a list of all functions that the
> exception propagated through when it was caught.
> The exception trace is almost identical to a stack trace most of the
> time, though there can be complications if another exception occurs
> during exception handling, or if code handles an exception and
> throws another one (in the latter case, it's still useful to carry
> information on the original exception around).
In my implementation the stack is physically unwound when an exception
handler finishes, not when it starts. This means that if an exception
handler throws another exception (or rethrows the same exception),
then the stack trace will include the original trace which led to the
previous exception, plus the trace inside the exception handler, plus
anything after that.
The trace is materialized as an object from scanned stack only when
needed, usually after an exception escapes the toplevel.
> However, this exception trace is just debugging information and can
> be carried in string (text) form. The software isn't supposed to
> base decisions on the contents of the exception trace.
Indeed it's suitable only for ultimately showing it to a human.
I don't want programs to make decisions basing on the stack trace.
But I do want - basing on the exception itself, which means it should
be something more than a string.
> Or the problem is something that might happen. In that case, throwing
> an exception isn't a good solution - you might be aborting all kinds
> of higher-level transactions you don't know about.
They are responsible for their cleanup in case the code they call
throws an exception. This is usually done by bracketing constructs
which guarantee that something is done no matter whether the given
code finishes normally or fails.
If exceptions are supported at all, no matter whether they are
machine-readable objects or text messages, then code must be prepared
for proper cleanup if they appear. Especially in a dynamically typed
language where various problems are not caught at compile time but
show up at runtime as exceptions.
> Or, the higher-level transactions would have to write exception
> handlers to make sure that their transactions are completed, and
> they'd have to inspect any exception that percolates up and check
> whether it's a failure or something they're supposed to handle.
> Which means they have to know what kinds of exceptions might come
> from the bowels of the lower layers,
No, they only need to know the kinds of exceptions they are supposed
to handle.
--
__("< Marcin Kowalczyk
\__/ qrczak@xxxxxxxxxx
^^ http://qrnik.knm.org.pl/~qrczak/
.
- Follow-Ups:
- Re: Benefits of Dynamic Typing
- From: Joachim Durchholz
- Re: Benefits of Dynamic Typing
- References:
- Re: Benefits of Dynamic Typing
- From: Marcin 'Qrczak' Kowalczyk
- Re: Benefits of Dynamic Typing
- From: Joachim Durchholz
- Re: Benefits of Dynamic Typing
- From: Marcin 'Qrczak' Kowalczyk
- Re: Benefits of Dynamic Typing
- From: Joachim Durchholz
- Re: Benefits of Dynamic Typing
- From: Marcin 'Qrczak' Kowalczyk
- Re: Benefits of Dynamic Typing
- From: Joachim Durchholz
- Re: Benefits of Dynamic Typing
- Prev by Date: Re: Benefits of Dynamic Typing
- Next by Date: Re: Benefits of Dynamic Typing
- Previous by thread: Re: Benefits of Dynamic Typing
- Next by thread: Re: Benefits of Dynamic Typing
- Index(es):
Relevant Pages
|
Loading