[mercury-users] exceptions considered bloody annoying

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Apr 16 14:05:00 AEST 2002


Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
	* For example, in Okasaki's "Purely Functional Data Structures", he
	  suggests using using an exception to signal when an already-present
	  member of a set data structure is being inserted.  If the exception is
	  caught, the insert operation reduces to the identity function and no
	  extra memory is allocated.  Otherwise the insert operation proceeds as
	  per usual.
	
This has always seemed to me like a silly approach.
It's far better to define one's interfaces so that they make sense
as often as possible.  The operation
    union_element_set :: a -> Set a -> Set a
should have the semantics
    abs(union_element_set x s) = abs(s) U {abs(x)}
where abs is the abstraction function.  I'm in the process of crunching
some real data now, and life (already difficult), would be a LOT harder
if I had to insert my own checks to program around unmathematical restrictions
that only make interfaces pointlessly complicated, and error-prone to use.

	> Quick quiz: does anyone regularly catch exceptions other than at the very
	> top level of their program? How often do people find themselves using
	> "throw" compared to just "error"?
	
	The classic example is web-server plug-ins.  You don't want your server
	to fall over just because some third-party plug-in throws an exception.
	You have to catch it, return the world to a sane state, and carry on.
	
An even older example:  Auckland University had a teaching language called
Small.  So that the load-and-go compiler could be written in iteself,
exceptions were added to the language.  You wrote
    FAULT PROCEDURE <name>(<arguments>) <body>;
They were like integer procedures.  Normal termination of the <body> meant
result 0 (unless you chose to return something else, abnormal
termination mean result non-0.  By today's standards, not a very powerful
mechanism, but adequate to ensure that dynamically loaded code could
"crash" without killing the entire system.  The only variables a dynamically
loaded component could modify were the ones you passed as parameters.

I note that Eiffel's exception handling mechanism is about as unlike 'throw'
as you can get.
--------------------------------------------------------------------------
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