File: gprolog019.html

package info (click to toggle)
gprolog 1.3.0-6.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 13,512 kB
  • ctags: 8,954
  • sloc: ansic: 57,431; perl: 16,620; sh: 5,900; makefile: 1,284
file content (399 lines) | stat: -rw-r--r-- 15,858 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<!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.08">
<LINK rel="stylesheet" type="text/css" href="gprolog.css">
<TITLE>
Errors
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="gprolog018.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog016.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>

<H3 CLASS="subsection"><A NAME="htoc32">5.3</A>&nbsp;&nbsp;Errors</H3><UL>
<LI><A HREF="gprolog019.html#toc15">General format and error context</A>
<LI><A HREF="gprolog019.html#toc16">Instantiation error</A>
<LI><A HREF="gprolog019.html#toc17">Type error</A>
<LI><A HREF="gprolog019.html#toc18">Domain error</A>
<LI><A HREF="gprolog019.html#toc19">Existence error</A>
<LI><A HREF="gprolog019.html#toc20">Permission error</A>
<LI><A HREF="gprolog019.html#toc21">Representation error</A>
<LI><A HREF="gprolog019.html#toc22">Evaluation error</A>
<LI><A HREF="gprolog019.html#toc23">Resource error</A>
<LI><A HREF="gprolog019.html#toc24">Syntax error</A>
<LI><A HREF="gprolog019.html#toc25">System error</A>
</UL>

<A NAME="Errors"></A>
<A NAME="toc15"></A>
<H4 CLASS="subsubsection"><A NAME="htoc33">5.3.1</A>&nbsp;&nbsp;General format and error context</H4>
<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="gprolog022.html#catch/3">6.2.4</A>) and to raise an error using
<TT>throw/1</TT> (section&nbsp;<A HREF="gprolog022.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 CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list">
<PRE CLASS="verbatim">
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="gprolog045.html#set-bip-name/2">7.22.3</A>) and
<TT>current_bip_name/2</TT> (section&nbsp;<A HREF="gprolog045.html#current-bip-name/2">7.22.4</A>) are provided to
set and recover the name and the arity associated with 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 CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list">
<PRE CLASS="verbatim">
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>
<H4 CLASS="subsubsection"><A NAME="htoc34">5.3.2</A>&nbsp;&nbsp;Instantiation error</H4>
<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>
<H4 CLASS="subsubsection"><A NAME="htoc35">5.3.3</A>&nbsp;&nbsp;Type error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>atom</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>atomic</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>boolean</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>byte</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>callable</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>character</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>compound</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>evaluable</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>fd_bool_evaluable</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>fd_evaluable</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>fd_variable</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>float</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>in_byte</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>in_character</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>integer</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>list</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>number</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>predicate_indicator</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc36">5.3.4</A>&nbsp;&nbsp;Domain error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>atom_property</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>buffering_mode</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>character_code_list</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>close_option</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>date_time</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>eof_action</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>fd_labeling_option</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>flag_value</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>format_control_sequence</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>g_array_index</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>io_mode</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>non_empty_list</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>not_less_than_zero</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>operator_priority</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>operator_specifier</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>os_file_permission</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>os_file_property</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>os_path</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>predicate_property</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>prolog_flag</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>read_option</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>selectable_item</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>socket_address</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>socket_domain</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>source_sink</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>statistics_key</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>statistics_value</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream_option</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream_or_alias</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream_position</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream_property</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream_seek_method</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream_type</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>term_stream_or_alias</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>var_binding_option</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc37">5.3.5</A>&nbsp;&nbsp;Existence error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>procedure</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>source_sink</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc38">5.3.6</A>&nbsp;&nbsp;Permission error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>access</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>add_alias</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>close</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>create</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>input</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>modify</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>open</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>output</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>reposition</TT></UL>
and <I><TT>Permission</TT></I> is one of:
<UL CLASS="itemize"><LI CLASS="li-itemize"><TT>binary_stream</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>flag</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>operator</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>past_end_of_stream</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>private_procedure</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>source_sink</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>static_procedure</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>stream</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc39">5.3.7</A>&nbsp;&nbsp;Representation error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>character</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>character_code</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>in_character_code</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>max_arity</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>max_integer</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>min_integer</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc40">5.3.8</A>&nbsp;&nbsp;Evaluation error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>float_overflow</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>int_overflow</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>undefined</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>underflow</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc41">5.3.9</A>&nbsp;&nbsp;Resource error</H4>
<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 CLASS="itemize"><LI CLASS="li-itemize"><TT>print_object_not_linked</TT><BR>
<BR>
<LI CLASS="li-itemize"><TT>too_big_fd_constraint</TT><BR>
<BR>
<LI CLASS="li-itemize"><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>
<H4 CLASS="subsubsection"><A NAME="htoc42">5.3.10</A>&nbsp;&nbsp;Syntax error</H4>
<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>
<H4 CLASS="subsubsection"><A NAME="htoc43">5.3.11</A>&nbsp;&nbsp;System error</H4>
A system error can occur at any stage. A system error is generally
associated with 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-2007 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="gprolog018.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog016.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>