Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > d1f06a5336fd6bf4a381b72b8d2b5ce1 > files > 154

gprolog-1.2.16-3mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14">
<TITLE>
 Errors
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="manual018.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual016.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<HR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE>
<TR><TD><FONT SIZE=4><B><A NAME="htoc32">5.3</A></B></FONT></TD>
<TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Errors</B></FONT></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><UL>
<LI><A HREF="manual019.html#toc15"> General format and error context</A>
<LI><A HREF="manual019.html#toc16"> Instantiation error</A>
<LI><A HREF="manual019.html#toc17"> Type error</A>
<LI><A HREF="manual019.html#toc18"> Domain error</A>
<LI><A HREF="manual019.html#toc19"> Existence error</A>
<LI><A HREF="manual019.html#toc20"> Permission error</A>
<LI><A HREF="manual019.html#toc21"> Representation error</A>
<LI><A HREF="manual019.html#toc22"> Evaluation error</A>
<LI><A HREF="manual019.html#toc23"> Resource error</A>
<LI><A HREF="manual019.html#toc24"> Syntax error</A>
<LI><A HREF="manual019.html#toc25"> System error</A>
</UL>

<A NAME="Errors"></A><BR>
<A NAME="toc15"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc33">5.3.1</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>General format and error context</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="General-format-and-error-context"></A>
When an error occurs an exception of the form:
<TT>error(<I>ErrorTerm</I>, <I>Caller</I>)</TT> is raised.
<I><TT>ErrorTerm</TT></I> is a term specifying the error (detailed in next
sections) and <I><TT>Caller</TT></I> is a term specifying the context of
the error. The context is either the predicate indicator of the last invoked
built-in predicate or an atom giving general context information.<BR>
<BR>
Using exceptions allows the user both to recover an error using
<TT>catch/3</TT> (section&nbsp;<A HREF="manual022.html#catch/3">6.2.4</A>) and to raise an error using
<TT>throw/1</TT> (section&nbsp;<A HREF="manual022.html#catch/3">6.2.4</A>). <BR>
<BR>
To illustrate how to write error cases, let us write a predicate
<TT>my_pred(X)</TT> where <TT>X</TT> must be an integer:
<DL COMPACT=compact><DT><DD>
<PRE>
my_pred(X) :-
        (   nonvar(X) -&gt;
            true
        ;   throw(error(instantiation_error), my_pred/1)),
        ),
        (   integer(X) -&gt;
            true
        ;   throw(error(type_error(integer, X), my_pred/1))
        ),
        ...
</PRE></DL>
To help the user to write these error cases, a set of system predicates is
provided to raise errors. These predicates are of the form
<TT>'$pl_err_...'</TT> and they all refer to the implicit error context.
The predicates <TT>set_bip_name/2</TT> (section&nbsp;<A HREF="manual045.html#set-bip-name/2">7.22.3</A>) and
<TT>current_bip_name/2</TT> (section&nbsp;<A HREF="manual045.html#current-bip-name/2">7.22.4</A>) are provided to
set and recover the name and the arity associated to this context (an arity
&lt; 0 means that only the atom corresponding to the functor is significant).
Using these system predicates the user could define the above predicate as
follow:
<DL COMPACT=compact><DT><DD>
<PRE>
my_pred(X) :-
        set_bip_name(my_pred,1),
        (   nonvar(X) -&gt;
            true
        ;   '$pl_err_instantiation'
        ),
        (   integer(X) -&gt;
            true
        ;   '$pl_err_type'(integer, X)
        ),
        ...
</PRE></DL>
The following sections detail each kind of errors (and associated system
predicates).<BR>
<BR>
<A NAME="toc16"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc34">5.3.2</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Instantiation error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Instantiation-error"></A>
An instantiation error occurs when an argument or one of its components is
variable while an instantiated argument was expected.
<I><TT>ErrorTerm</TT></I> has the following form:
<TT>instantiation_error</TT>.<BR>
<BR>
The system predicate <TT>'$pl_err_instantiation'</TT> raises this
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc17"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc35">5.3.3</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Type error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Type-error"></A>
A type error occurs when the type of an argument or one of its components is
not the expected type (but not a variable). <I><TT>ErrorTerm</TT></I> has
the following form: <TT>type_error(<I>Type</I>, Culprit)</TT> where
<I><TT>Type</TT></I> is the expected type and <I><TT>Culprit</TT></I>
the argument which caused the error. <I><TT>Type</TT></I> is one of:
<UL><LI><TT>atom</TT><BR>
<BR>
<LI><TT>atomic</TT><BR>
<BR>
<LI><TT>boolean</TT><BR>
<BR>
<LI><TT>byte</TT><BR>
<BR>
<LI><TT>callable</TT><BR>
<BR>
<LI><TT>character</TT><BR>
<BR>
<LI><TT>compound</TT><BR>
<BR>
<LI><TT>evaluable</TT><BR>
<BR>
<LI><TT>fd_bool_evaluable</TT><BR>
<BR>
<LI><TT>fd_evaluable</TT><BR>
<BR>
<LI><TT>fd_variable</TT><BR>
<BR>
<LI><TT>float</TT><BR>
<BR>
<LI><TT>in_byte</TT><BR>
<BR>
<LI><TT>in_character</TT><BR>
<BR>
<LI><TT>integer</TT><BR>
<BR>
<LI><TT>list</TT><BR>
<BR>
<LI><TT>number</TT><BR>
<BR>
<LI><TT>predicate_indicator</TT><BR>
<BR>
<LI><TT>variable</TT></UL>
The system predicate <TT>'$pl_err_type'(Type, Culprit)</TT> raises this
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc18"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc36">5.3.4</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Domain error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Domain-error"></A>
A domain error occurs when the type of an argument is correct but its value
is outside the expected domain. <I><TT>ErrorTerm</TT></I> has the
following form: <TT>domain_error(<I>Domain</I>, <I>Culprit</I>)</TT>
where <I><TT>Domain</TT></I> is the expected domain and
<I><TT>Culprit</TT></I> the argument which caused the error.
<I><TT>Domain</TT></I> is one of:
<UL><LI><TT>atom_property</TT><BR>
<BR>
<LI><TT>buffering_mode</TT><BR>
<BR>
<LI><TT>character_code_list</TT><BR>
<BR>
<LI><TT>close_option</TT><BR>
<BR>
<LI><TT>date_time</TT><BR>
<BR>
<LI><TT>eof_action</TT><BR>
<BR>
<LI><TT>fd_labeling_option</TT><BR>
<BR>
<LI><TT>flag_value</TT><BR>
<BR>
<LI><TT>format_control_sequence</TT><BR>
<BR>
<LI><TT>g_array_index</TT><BR>
<BR>
<LI><TT>io_mode</TT><BR>
<BR>
<LI><TT>non_empty_list</TT><BR>
<BR>
<LI><TT>not_less_than_zero</TT><BR>
<BR>
<LI><TT>operator_priority</TT><BR>
<BR>
<LI><TT>operator_specifier</TT><BR>
<BR>
<LI><TT>os_file_permission</TT><BR>
<BR>
<LI><TT>os_file_property</TT><BR>
<BR>
<LI><TT>os_path</TT><BR>
<BR>
<LI><TT>predicate_property</TT><BR>
<BR>
<LI><TT>prolog_flag</TT><BR>
<BR>
<LI><TT>read_option</TT><BR>
<BR>
<LI><TT>selectable_item</TT><BR>
<BR>
<LI><TT>socket_address</TT><BR>
<BR>
<LI><TT>socket_domain</TT><BR>
<BR>
<LI><TT>source_sink</TT><BR>
<BR>
<LI><TT>statistics_key</TT><BR>
<BR>
<LI><TT>statistics_value</TT><BR>
<BR>
<LI><TT>stream</TT><BR>
<BR>
<LI><TT>stream_option</TT><BR>
<BR>
<LI><TT>stream_or_alias</TT><BR>
<BR>
<LI><TT>stream_position</TT><BR>
<BR>
<LI><TT>stream_property</TT><BR>
<BR>
<LI><TT>stream_seek_method</TT><BR>
<BR>
<LI><TT>stream_type</TT><BR>
<BR>
<LI><TT>term_stream_or_alias</TT><BR>
<BR>
<LI><TT>var_binding_option</TT><BR>
<BR>
<LI><TT>write_option</TT></UL>
The system predicate <TT>'$pl_err_domain'(Domain, Culprit)</TT> raises
this error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc19"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc37">5.3.5</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Existence error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Existence-error"></A>
an existence error occurs when an object on which an operation is to be
performed does not exist. <I><TT>ErrorTerm</TT></I> has the following
form: <TT>existence_error(<I>Object</I>, <I>Culprit</I>)</TT> where
<I><TT>Object</TT></I> is the type of the object and
<I><TT>Culprit</TT></I> the argument which caused the error.
<I><TT>Object</TT></I> is one of:
<UL><LI><TT>procedure</TT><BR>
<BR>
<LI><TT>source_sink</TT><BR>
<BR>
<LI><TT>stream</TT></UL>
The system predicate <TT>'$pl_err_existence'(Object, Culprit)</TT> raises
this error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc20"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc38">5.3.6</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Permission error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Permission-error"></A>
A permission error occurs when an attempt to perform a prohibited operation
is made. <I><TT>ErrorTerm</TT></I> has the following form:
<TT>permission_error(<I>Operation</I>, <I>Permission</I>,
<I>Culprit</I>)</TT> where <I><TT>Operation</TT></I> is the operation which
caused the error, <I><TT>Permission</TT></I> the type of the tried
permission and <I><TT>Culprit</TT></I> the argument which caused the
error. <I><TT>Operation</TT></I> is one of:
<UL><LI><TT>access</TT><BR>
<BR>
<LI><TT>add_alias</TT><BR>
<BR>
<LI><TT>close</TT><BR>
<BR>
<LI><TT>create</TT><BR>
<BR>
<LI><TT>input</TT><BR>
<BR>
<LI><TT>modify</TT><BR>
<BR>
<LI><TT>open</TT><BR>
<BR>
<LI><TT>output</TT><BR>
<BR>
<LI><TT>reposition</TT></UL>
and <I><TT>Permission</TT></I> is one of:
<UL><LI><TT>binary_stream</TT><BR>
<BR>
<LI><TT>flag</TT><BR>
<BR>
<LI><TT>operator</TT><BR>
<BR>
<LI><TT>past_end_of_stream</TT><BR>
<BR>
<LI><TT>private_procedure</TT><BR>
<BR>
<LI><TT>source_sink</TT><BR>
<BR>
<LI><TT>static_procedure</TT><BR>
<BR>
<LI><TT>stream</TT><BR>
<BR>
<LI><TT>text_stream</TT></UL>
The system predicate <TT>'$pl_err_permission'(Operation, Permission,
Culprit)</TT> raises this error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc21"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc39">5.3.7</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Representation error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Representation-error"></A>
A representation error occurs when an implementation limit has been
breached. <I><TT>ErrorTerm</TT></I> has the following form:
<TT>representation_error(<I>Limit</I>)</TT> where <I><TT>Limit</TT></I>
is the name of the reached limit. <I><TT>Limit</TT></I> is one of:
<UL><LI><TT>character</TT><BR>
<BR>
<LI><TT>character_code</TT><BR>
<BR>
<LI><TT>in_character_code</TT><BR>
<BR>
<LI><TT>max_arity</TT><BR>
<BR>
<LI><TT>max_integer</TT><BR>
<BR>
<LI><TT>min_integer</TT><BR>
<BR>
<LI><TT>too_many_variables</TT></UL>
The errors <TT>max_integer</TT> and <TT>min_integer</TT> are not currently
implemented.<BR>
<BR>
The system predicate <TT>'$pl_err_representation'(Limit)</TT> raises this 
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc22"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc40">5.3.8</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Evaluation error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Evaluation-error"></A>
An evaluation error occurs when an arithmetic expression gives rise to
an exceptional value. <I><TT>ErrorTerm</TT></I> has the following form:
<TT>evaluation_error(<I>Error</I>)</TT> where <I><TT>Error</TT></I> is
the name of the error. <I><TT>Error</TT></I> is one of:
<UL><LI><TT>float_overflow</TT><BR>
<BR>
<LI><TT>int_overflow</TT><BR>
<BR>
<LI><TT>undefined</TT><BR>
<BR>
<LI><TT>underflow</TT><BR>
<BR>
<LI><TT>zero_divisor</TT></UL>
The errors <TT>float_overflow</TT>, <TT>int_overflow</TT>,
<TT>undefined</TT> and <TT>underflow</TT> are not currently
implemented.<BR>
<BR>
The system predicate <TT>'$pl_err_evaluation'(Error)</TT> raises this
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc23"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc41">5.3.9</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Resource error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Resource-error"></A>
A resource error occurs when GNU Prolog does not have enough resources.
<I><TT>ErrorTerm</TT></I> has the following form:
<TT>resource_error(<I>Resource</I>)</TT> where <I><TT>Resource</TT></I> is the
name of the resource. <I><TT>Resource</TT></I> is one of:
<UL><LI><TT>print_object_not_linked</TT><BR>
<BR>
<LI><TT>too_big_fd_constraint</TT><BR>
<BR>
<LI><TT>too_many_open_streams</TT></UL>
The system predicate <TT>'$pl_err_resource'(Resource)</TT> raises this
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc24"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc42">5.3.10</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Syntax error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Syntax-error"></A>
A syntax error occurs when a sequence of character does not conform to the
syntax of terms. <I><TT>ErrorTerm</TT></I> has the following form:
<TT>syntax_error(<I>Error</I>)</TT> where <I><TT>Error</TT></I> is an
atom explaining the error.<BR>
<BR>
The system predicate <TT>'$pl_err_syntax'(Error)</TT> raises this
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>
<A NAME="toc25"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc43">5.3.11</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>System error</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
A system error can occur at any stage. A system error is generally
associated to an external component (e.g. operating system).
<I><TT>ErrorTerm</TT></I> has the following form:
<TT>system_error(<I>Error</I>)</TT> where <I><TT>Error</TT></I> is an
atom explaining the error. This is an extension to ISO which only defines
<TT>system_error</TT> without arguments.<BR>
<BR>
The system predicate <TT>'$pl_err_system'(Error)</TT> raises this
error in the current error context (section&nbsp;<A HREF="#General-format-and-error-context">5.3.1</A>).<BR>
<BR>

<HR SIZE=2>
Copyright (C) 1999-2002 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="manual018.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual016.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
</BODY>
</HTML>