[mercury-users] Exception handling documentation.
Paul Bone
pbone at csse.unimelb.edu.au
Thu Jul 17 15:52:18 AEST 2008
On Thu, Jul 17, 2008 at 03:43:02PM +1000, Julien Fischer wrote:
>
> On Thu, 17 Jul 2008, Paul Bone wrote:
>
> >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.
>
> It requires that it is cc_multi, not 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.
>
> No, semantically there are more solutions but we are *committing* to one.
> In the case of try_io there are multiple possible I/O states.
>
How can that help me? I'd like my write predicate to be deterministic so
I have to throw away the cc_multi somewhere.
I tried putting the call to try_io in a some scope, this didn't work either:
% Write the feedback to the given output stream. This predicate is
% seperated from the above predicate so that the mode checker is happy with
% the use of try_io.
%
/* ### 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) :-
some [!IO2, ExcpResPrime]
(
!:IO2 = !.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), ExcpResPrime, !IO2),
ExcpRes = ExcpResPrime,
!.IO2 = !:IO
),
*snip*
-------------- 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/9669ecaf/attachment.sig>
More information about the users
mailing list