[mercury-users] Re: Exception semantics

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 20 10:47:36 AEDT 2000


On 19-Jan-2000, Renaud Paquay <rpa at miscrit.be> wrote:
> 
> I was just wondering about the semantics of exceptions when
> I saw some Mercury code I wrote some time ago.
> 
> I wrote this simple predicate:
> 
> :- pred ole_check(int::in) is det.
> ole_check(HResult):-
> 	(
> 		HResult < 0
> 	->
> 		error("...")
> 	;
> 		true
> 	).
> 
> The compiler may well choose to remove calls to ole_check, because
> its declarative semantics is that it does nothing (in -> det).
> However, it is in practice very important the code is executed
> in my case, because "HResult" is a return code from a call to a
> COM server. I do a "ole_check" after every call to the COM server.
> If I miss one, I will be in trouble...
> 
> Am I missing something?

1.  Don't write code like that.
    Instead use e.g.

    	:- func ole_check(int, T) = T.
	ole_check(HResult, Val0) = Val :-
		(	
			HResult < 0
		->
			error("...")
		;
			Val = Val0
		).

2.  If you ignore recommendation 1, then make sure that you
    compile your code with the `--fully-strict' option
    (currently this is the default).
    This will guarantee that the compiler will not optimize
    away calls to error/1 or other exceptions.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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