[m-dev.] try syntax
Paul Bone
pbone at csse.unimelb.edu.au
Fri Jan 23 09:43:37 AEDT 2009
On Thu, Jan 22, 2009 at 05:10:03PM +1100, Peter Wang 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)
>
> 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))
Should the above (catch all exceptions) be implicity defined as
rethrowing that exception. That is. I want to be able to omit this if
all I'm going to do is rethrow the acception, but I want the ability to
specify it incase I want some non-default behaviour.
> ) 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))
> )
> )
>
> Peter
This is a good idea.
-------------- 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/developers/attachments/20090123/b9943214/attachment.sig>
More information about the developers
mailing list