Subject: Re: exception/3

From: Jan Wielemaker <[email-masked]>
Date: Tue, 2 Nov 1999 22:05:32 +0100

> why doens't exception work the way it is described in the manual?
> (version 3.2.9 on HP-UX 10.20)

Maybe this should be called maintenance problems.  One might also
call is improved understanding :-)

Thanks fot noting, but the undefined_predicate interception is no
longer called.

Undefined predicates are ignored if the unknown/2 flag is active for
the implied module (or the predicate is defined using dynamic/1) and
otherwise cause an exception in the ISO-sense (i.e. using throw/1).

> to exception/3 at all ??? (Is there a difference between an
> undefined predicate and an undefined procedure?)

No :-)

> Yes
> 7 ?- jan.
> [WARNING: Undefined predicate: `jan/0']

This works a little different as the toplevel tries to correct the
goal (DWIM) and if this fails it just prints a message.  Maybe it
should call the undefined predicate nevertheless to get consistent
behaviour to the user.

> 8 ?- [user].
> 2 |: jan :- piet.
> 2 |:
> user compiled, 0.00 sec, 0 bytes.
> 
> Yes
> 9 ?- jan.
> [WARNING: Undefined procedure: piet/0]
>    Exception: (  8) piet ?                       

This is the normal behaviour of a running program.

> Another question, is there a way to `hook' print_message/2 so that
> I can provide message printers for my own exceptions?

You can define additional translation to textual representation by
adding clauses to prolog:message/3 (a multifile predicate):

:- multifile prolog:message/3.

prolog:message(i_do_not_like(X)) -->
	[ 'I no not like ', X ].

should produce a nice message if I do throw(i_do_not_like(fortran)).

See boot/messages.  At the moment there is no dynamic hook into
print_message/2.  If you need it, please let me know.

	--- Jan