[m-dev.] try syntax
Peter Ross
pdross at gmail.com
Thu Jan 22 17:22:43 AEDT 2009
On Thu, Jan 22, 2009 at 5:10 PM, Peter Wang <novalazy at gmail.com> wrote:
> Hi,
>
> Catching exceptions is too cumbersome. I think we should have built in
> syntax, e.g. (adjust accordingly if the parser is too dumb)
>
I agree, I guess the reason we don't have it as I'm pretty sure the
compiler doesn't use a lot of exception handling code, unlike the
servers that we write.
> try [io(!IO)] (
> f(X, Y, Z, !IO)
> ) then (
> on_success(X, Y, Z) % outputs in scope
> ) else (
> on_failure
> ) catch [_ : exc1] ( % zero or more catch blocks
> on_catch_exc1
> ) catch [E] (
> rethrow(exception(E))
> ) finally ( % optional
> cleanup
> )
>
> io(!IO) selects try_io.
> store(!S) selects try_store.
> all(Solutions) selects try_all.
> Otherwise use try.
>
> We'd implement it by doing a tranformation to call the underlying
> predicates in the exception module. The following assumes no `finally'
> block.
>
> try_io(
> (pred({X0, Y0, Z0}::out, !.IO::di, !:IO::uo) is det :-
> f(X0, Y0, Z0, !IO)
> ), TryResult, !IO),
> (
> TryResult = succeeded({X, Y, Z}),
> on_success(X, Y, Z)
> ;
> TryResult = failed,
> on_failure
> ;
> TryResult = exception(E0),
> ( univ_to_type(E0, _ : exc1) ->
> on_catch_exc1
> ; univ_to_type(E0, E) ->
> rethrow(exception(E))
> )
> )
>
What would be the behavour if you don't have a catch block that
succeeds? In other words what goes in the last else in the above
transformation?
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list