Home > Archive > Prolog > September 2006 > SWI-Prolog : Constructing Exceptions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SWI-Prolog : Constructing Exceptions
|
|
| roschler 2006-09-17, 8:04 am |
| 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.
Note: I want to throw the error from my own Prolog code, not from a
Foreign Language library.
Thanks.
| |
| Jan Wielemaker 2006-09-18, 4:00 am |
| On 2006-09-17, roschler <robert.oschler@gmail.com> 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
|
|
|
|
|