[mercury-users] Exception handling documentation.

Paul Bone pbone at csse.unimelb.edu.au
Thu Jul 17 15:20:03 AEST 2008

On Thu, Jul 17, 2008 at 02:30:30PM +1000, Julien Fischer wrote:
> On Thu, 17 Jul 2008, Paul Bone wrote:
> >
> >io.close_output throws an exception if bad stuff happens.  I don't see
> >any information in the language reference guide about exceptions, this
> >is probably a bug.
> exceptions are a library feature so they are documented in the library
> reference guide.  (The reference manual of course documents the 
> determinism erroneous).

Ah,  Found it :-).

> >Alot of the io package returns errors as part of their return value.
> >Should this be consitant and always return a type that can be used to
> >check for errors?
> It is fairly consistent isn't it.  Those that throw an exception
> put the error inside of the exception.

Some throw exceptions and others return values.  This is the bit that's
not consitant.

When I use try_io to try a closure and catch exceptions it requires that
it's parent be cc_multi or multi, and that that predicate's parent is
cc_multi or multi.  I thought that the idea of cc_multi was that it
behaved like det but semantically there could be more solutions that
would _never_ be found.

/* ### In `write2'(in, in, in, out, di, uo): */
/* ###   error: determinism declaration not satisfied. */
/* ###   Declared `det', inferred `multi'. */
:- pred write2(output_stream::in, string::in, feedback_state::in,
    feedback_write_result::out, io::di, io::uo) is det.

write2(Stream, ProgName, Feedback, Res, !IO) :-
/* ###   call to `exception.try_io'((pred(out, di, uo) is det), */
/* ###   out((exception.cannot_fail)), di, uo) can succeed more than */
/* ###   once. */
/* ### Error: call to predicate `exception.try_io'/4 with determinism */
/* ###   `cc_multi' occurs in a context which requires all solutions. */
    try_io(write3(Stream, ProgName, Feedback), ExcpRes, !IO),
        ExcpRes = succeeded(_),
        Res = ok
        ExcpRes = exception(ExcpUniv),

        % If the exception is not a type we exected then re-throw it.
            univ_to_type(ExcpUniv, Excp)
            Res = write_error(Excp)

Mercury Compiler, version rotd-2008-07-07, configured for i686-pc-linux-gnu
Copyright (C) 1993-2008 The University of Melbourne

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20080717/58e51afb/attachment.sig>

More information about the users mailing list