[mercury-users] exceptions and cc_multi

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 29 18:40:56 AEDT 2000


On 29-Nov-2000, Michael Day <mikeday at corplink.com.au> wrote:
> 
> Why are try and try_io both cc_multi,

Because the result depends not only on the value of the higher-order
argument, but also on how the compiler chooses to evaluate that
argument.  For example, you could call some code that could get two
different exceptions depending on the order of execution,
e.g. `throw(1), throw(2)'.  Or you could call code that might or
might not throw an exception, depending on the order of execution
e.g. `throw(1), fail'.

> and how does one handle exceptions in det code without propogating
> the cc_multiness all the way back up to main?

You can use `promise_only_solution'.

However, this should only be done if you are sure that the result
(if any) will be the same regardless of whether an exception is thrown.

For example, you may have two different algorithms for calculating
the same thing; one algorithm is fast, but only works some of the
time, while the other algorithm is guaranteed to work in all cases
but is less efficient.  You can define a wrapper which calls
the first algorithm inside `try', and then if it got an exception,
calls the second algorithm.  So long as the two algorithms do indeed
compute the same results, it is safe to put the wrapper inside
`promise_only_solution'.

I said "if any" above since it is OK to use `promise_only_solution' in
cases where the handler can rethrow the exception or can map it to a
different exception.

In many cases, propagating the cc_multiness all the way back up to
main is probably the right solution.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  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