Subject: Re: [SWIPL] Type error vs. silent failure

From: Paul Singleton <[email-masked]>
Date: Fri, 26 Oct 2001 14:01:02 +0100

Jan Wielemaker wrote:

> Only in some really performance-critical situations I sometimes estimate
> whether using catch/3 or checking is more efficient.  Note that catch/3
> is not cheap for many reasons.  The call is a meta-call, you have to
> push the goal, template and recovery onto the stack and if an exception
> happens another expensive unwinding and meta-call must take place.

Please reassure us that the "exception doesn't happen" cost is nothing
to be afraid of :-)

If not, is it inherently expensive, or could it e.g. be compiled as a
special case?

> Next is coding:
> 	
> 	catch(nth1(N, List, E), error(type_error(_), _), fail)
> 
> isn't really pretty, but 
> 
> 	catch(nth1(N, List, E), _, fail).
> 
> May give some undesired results.  Maybe nth1/3 isn't around and your
> goal now fails silently rather then with an error.  Maybe the system
> runs out of stack, but this code will silently fail!

Java pragmatically distinguishes "checked" and "unchecked" exceptions,
then imposes static checking on checked exceptions (must be either
handled or explicitly declared to be possibly thrown).  Is it feasible
to do such static checking on (some practically useful subset of)
ISO or SWI Prolog?

Paul Singleton

PS I am not suggesting that it must be a good idea because Java does 
it, but that software engineering issues like this are essentially
pragmatic, not theological, and that there's been enough experience
with the Java scheme for us to decide whether it was well judged or
misconceived...