root/trunk/manuals/userman/errors.html

Revision 4621, 6.8 KB (checked in by pmoura, 6 weeks ago)

Improved navigation bar in the XHTML manual pages.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
6
7<head>
8    <meta http-equiv="content-type" content="application/xml+xhtml; charset=utf-8" />
9    <title>Logtalk user manual: error handling</title>
10    <link rel="stylesheet" href="../screen.css" type="text/css" media="screen"/>
11    <link rel="stylesheet" href="../print.css" type="text/css" media="print"/>
12</head>
13
14<body>
15
16<div class="top-left">Logtalk user manual</div> 
17<div class="top-right">Error handling</div>
18<div class="bottom-left"><span class="page"/></div> 
19<div class="bottom-right"><span class="page"/></div>
20<div class="navtop"><a href="../index.html">Contents</a> &gt; <a href="index.html">User Manual</a> &gt; Error handling</div>
21
22<h1 id="errors_errors">Error handling</h1>
23
24<p>
25All error/exception handling is done in Logtalk by using the ISO defined <code>catch/3</code> and <code>throw/1</code> predicates <a title="ISO Prolog Standard" href="../bibliography.html#ISO95">[ISO 95]</a>. Some Prolog compilers do not implement these predicates or, if they do, the implementation is not compatible with the standard. Furthermore, the nature of these predicates does not allow their definition by the user. For these reasons, we should check our Prolog compiler before trying to add error handling code to your Logtalk applications.
26</p>
27<p>
28Errors thrown by Logtalk defined built-in predicates have the following format:
29</p>
30<pre>error(Error, Goal)</pre>
31<p>
32For example:
33</p>
34<pre>error(type_error(object_identifier, 33), current_object(33))</pre>
35<p>
36Errors thrown while processing a message have the following format:
37</p>
38<pre>error(Error, Message, Sender)</pre>
39<p>
40For example:
41</p>
42<pre>error(permission_error(modify, private_predicate, p(_)), foo::abolish(p/1), user)</pre>
43<p>
44The <code>Goal</code>, <code>Message</code>, and <code>Sender</code> can be variables when the corresponding information is not available.
45</p>
46
47<h2>Compiler warnings and errors<a id="errors_compiler"></a></h2>
48
49<p>
50The current Logtalk compiler uses the <code>read_term/3</code> ISO Prolog defined built-in predicate to read and process a Logtalk source file. One consequence of this is that invalid Prolog terms or syntax errors may abort the compilation process with limited information given to the user (due to the inherent limitations of the <code>read_term/3</code> predicate).
51</p>
52<p>
53If all the terms in a source file are valid, then there is a set of errors or potential errors, described below, that the compiler will try to detect and report, depending on the used compiler flags (see the <a href="installing.html#options">Installing and running Logtalk</a> section of this manual for details).
54</p>
55
56<h3 id="errors_wunknown">Unknown entities</h3>
57
58<p>
59The Logtalk compiler will warn us of any referenced entity that is not currently loaded. The warning may reveal a misspell entity name or just an entity that it will be loaded next.
60</p>
61
62<h3 id="errors_wsingletons">Singleton variables</h3>
63
64<p>
65Singleton variables in a clause are often misspell variables and, as such, one of the most common errors when programming in Prolog. If your Prolog compiler complies with the Prolog ISO standard or at least supports the ISO predicate <code>read_term/3</code> called with the option <code>singletons(S)</code>, then the Logtalk compiler will warn us of any singleton it finds while compiling a Logtalk entity.
66</p>
67
68<h3 id="errors_wprolog">Redefinition of Prolog built-in predicates</h3>
69
70<p>
71The Logtalk compiler will warn us of any redefinition of a Prolog built-in predicate inside an object or category. Sometimes the redefinition is intended. In other cases, the user may not be aware that the subjacent Prolog compiler may already provide the predicate as a built-in or we may want to ensure code portability among several Prolog compilers with different sets of built-in predicates.
72</p>
73
74<h3 id="errors_wpredicates">Redefinition of Logtalk built-in predicates</h3>
75
76<p>
77Similar to the redefinition of Prolog built-in predicates, the Logtalk compiler will warn us if we try to redefine a Logtalk built-in. The redefinition will probably be an error in almost all (if not all) cases.
78</p>
79
80<h3 id="errors_wmethods">Redefinition of Logtalk built-in methods</h3>
81
82<p>
83An error will be thrown if we attempt to redefine a Logtalk built-in method inside an entity. The default behavior is to report the error and abort the compilation of the offending entity.
84</p>
85
86<h3 id="errors_wmisspell">Misspell calls of local predicates</h3>
87
88<p>
89A warning will be reported if Logtalk finds (in the body of a predicate definition) a call to a local predicate that is not defined, built-in (either in Prolog or in Logtalk) or declared dynamic. In most cases these calls are simple misspell errors.
90</p>
91
92<h3 id="errors_wportability">Portability warnings</h3>
93
94<p>
95A warning will be reported if a predicate clause contains a call to a non-ISO specified built-in predicate or to a non-ISO specified arithmetic function.
96</p>
97
98<h3 id="errors_wothers">Other warnings and errors</h3>
99
100<p>
101The Logtalk compiler will throw an error if it finds a predicate clause or a directive that cannot be parsed. The default behavior is to report the error and abort the compilation of the offending entity.
102</p>
103
104<h2 id="errors_runtime">Runtime errors</h2>
105
106<p>
107This session briefly describes runtime errors that result from misuse of Logtalk built-in predicates, built-in methods or from message sending. For a complete and detailed description of runtime errors please consult the <a title="Consult reference manual" href="../refman/index.html">Reference Manual</a>.
108</p>
109
110<h3 id="errors_predicates">Logtalk built-in predicates</h3>
111
112<p>
113All Logtalk built-in predicates checks the type and mode of the calling arguments, throwing an exception in case of misuse.
114</p>
115
116<h3 id="errors_methods">Logtalk built-in methods</h3>
117
118<p>
119Every Logtalk built-in method checks the type and mode of the calling arguments, throwing an exception in case of misuse.
120</p>
121
122<h3 id="errors_sending">Message sending</h3>
123
124<p>
125The message sending mechanisms always check if the receiver of a message is a defined object and if the message corresponds to a declared predicate within the scope of the sender.
126</p>
127
128<div class="footer">
129    <div class="copyright">
130        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/> 
131        <span>Last updated on: October 31, 2008</span>
132    </div>
133    <div class="navbottom">
134        <span><a href="threads.html">previous</a> | <a href="../glossary.html">glossary</a> | <a href="documenting.html">next</a></span><br/>
135        <span><a href="http://validator.w3.org/check/referer">XHTML</a> + <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a></span>
136    </div>
137</div>
138
139</body>
140
141</html>
Note: See TracBrowser for help on using the browser.