[m-dev.] cc_multi or det ?

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Aug 7 15:22:05 AEST 2001


On 07-Aug-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> 
> I don't understand how exceptions give a wider scope for introducing bugs.
> Is that because you forget to write handlers for them?

In languages like C++ that have manual memory management,
it is very easy to leak resources when an exception is thrown.
You need to program very very carefully to avoid resource leaks
in the presence of exceptions.

In C++ it's also very easy to crash your program by throwing
an exception in a destructor that was called during stack
unwinding while another exception is already being thrown.
This can be avoided, but it does require a detailed knowledge
of C++'s exception handling model, and explicit code to
catch and ignore (or log) exceptions that occur inside
destructors during stack unwinding.

Even in languages like Java that have automatic memory management,
and `try ... finally' for cleanup of non-memory resources,
programming safely in the presence of exceptions poses some 
challenges, due to the presence of mutable data structures.
it's possible for an exception thrown at an inopportune
time to leave a data structure in an invalid state,
with it's class invariant not satisfied.
You need to program quite carefully to avoid such problems,
making sure that member functions which temporarily violate
class invariants don't call other functions which could
throw exceptions while the class invariant isn't satisfied,
unless they are protected by an exception handler.

These problems don't apply so much to languages like Prolog and Mercury 
where mutable data structures that persist after exceptions are used
only rarely.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list