Re: SWI-Prolog : Constructing Exceptions



On 2006-09-17, roschler <robert.oschler@xxxxxxxxx> wrote:
I've been reading the 5.6 reference manual about Exceptions. I want to
construct my own and throw them. I found the manual page on Signal
handling, but I'm still a little vague on where to find the error
helper functions. For example, in one of the stock PL files
distributed with SWI-Prolog there is this line:

throw(error(permission_error(write, index_file, Dir), _))

This is a stream permission error exception I believe. Where can I
find the list of "error()" predicates so I know how to construct my
error object; especially one that will work well with "print_message"?
In my case I'm reading information from a file with get0/1, and I
intend to throw an exception if the resulting string I'm building is
too long.

Several options:

* Check out the ISO Prolog standard which describes these terms.
* Check the source for print_message/2 in pl/boot/messages.pl.
* Find a goal from which you know it gives the desired message
and use ?- catch(Goal, Error, true).

Ideally, this should of course all be documented ...

--- Jan
.