[mercury-users] Heap and Stack exception handling in Mercury?

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 27 18:05:56 AEDT 2002


On 26-Nov-2002, Sander van den Berg <xkb at hypernation.net> wrote:
> I have some more questions about exception handling. How does Mercury handle 
> "system exceptions" like Heap- and stack errors

In the current implementation, heap and stack overflow errors do not result
in Mercury exceptions, they just result in a run-time error (i.e. the
program issues an error message and then terminates).

If recovering from heap overflow is important, I think it should
be possible to do so by using the hlc.gc grade, and installing a C
out-of-heap handler (see GC_oom_func in boehm_gc/include/gc.h) that calls
Mercury code which throws an exception.  Probably the Mercury runtime
system ought to do this automatically in the hlc.gc grade, but until now
there has been little demand for this, so we haven't gotten around to it.

Likewise it would be possible to add code to check for stack overflow
at each procedure call, and throw a Mercury exception if the stack overflows,
rather than the current approach of using the system's virtual memory
protection to detect stack overflow, which only allows overflows to be
reported as run-time errors rather than as Mercury exceptions.
But this would have a performance impact.  There has not been much
demand for this either.

Many (but not all) of the other kinds of errors which might result in
processor exceptions, such as division by zero or array indexing errors,
are checked for in the Mercury standard library code and do result in
Mercury exceptions rather than run-time errors.

> and kill signals for example. 
> Does it handle a-synchronous exceptions at all?

The Mercury standard library does not have any direct support for
asynchronous exception handling.  However, it is possible to use
the foreign language interface for this.  For an example, see the
file `timeout.m' in the `deep_profiler' directory in a recent
release-of-the-day version of the mercury-compiler source distribution.

-- 
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-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list