File: Errors.html

package info (click to toggle)
octave 10.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 145,388 kB
  • sloc: cpp: 335,976; ansic: 82,241; fortran: 20,963; objc: 9,402; sh: 8,756; yacc: 4,392; lex: 4,333; perl: 1,544; java: 1,366; awk: 1,259; makefile: 660; xml: 192
file content (125 lines) | stat: -rw-r--r-- 5,748 bytes parent folder | download
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
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Errors (GNU Octave (version 10.3.0))</title>

<meta name="description" content="Errors (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Errors (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Getting-Started.html" rel="up" title="Getting Started">
<link href="Executable-Octave-Programs.html" rel="next" title="Executable Octave Programs">
<link href="Command-Line-Editing.html" rel="prev" title="Command Line Editing">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<div class="section-level-extent" id="Errors">
<div class="nav-panel">
<p>
Next: <a href="Executable-Octave-Programs.html" accesskey="n" rel="next">Executable Octave Programs</a>, Previous: <a href="Command-Line-Editing.html" accesskey="p" rel="prev">Command Line Editing</a>, Up: <a href="Getting-Started.html" accesskey="u" rel="up">Getting Started</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="How-Octave-Reports-Errors"><span>2.5 How Octave Reports Errors<a class="copiable-link" href="#How-Octave-Reports-Errors"> &para;</a></span></h3>
<a class="index-entry-id" id="index-error-messages"></a>
<a class="index-entry-id" id="index-messages_002c-error"></a>

<p>Octave reports two kinds of errors for invalid programs.
</p>
<p>A <em class="dfn">parse error</em> occurs if Octave cannot understand something you
have typed.  For example, if you misspell a keyword,
</p>
<div class="example">
<pre class="example-preformatted">octave:13&gt; function z = f (x, y) z = x ||| 2; endfunction
</pre></div>

<p>Octave will respond immediately with a message like this:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">parse error:

  syntax error

&gt;&gt;&gt; function z = f (x, y) z = x ||| y; endfunction
                                  ^
</pre></div></div>

<p>For most parse errors, Octave uses a caret (&lsquo;<samp class="samp">^</samp>&rsquo;) to mark the point
on the line where it was unable to make sense of your input.  In this
case, Octave generated an error message because the keyword for
the logical or operator (<code class="code">||</code>) was misspelled.  It marked the error
at the third &lsquo;<samp class="samp">|</samp>&rsquo; because the code leading up to this was correct
but the final &lsquo;<samp class="samp">|</samp>&rsquo; was not understood.
</p>
<p>Another class of error message occurs at evaluation time.  These
errors are called <em class="dfn">run-time errors</em>, or sometimes
<em class="dfn">evaluation errors</em>, because they occur when your program is being
<em class="dfn">run</em>, or <em class="dfn">evaluated</em>.  For example, if after correcting the
mistake in the previous function definition, you type
</p>
<div class="example">
<pre class="example-preformatted">octave:13&gt; f ()
</pre></div>

<p>Octave will respond with
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">error: `x' undefined near line 1 column 24
error: called from:
error:   f at line 1, column 22
</pre></div></div>

<p>This error message has several parts, and gives quite a bit of
information to help you locate the source of the error.  The messages
are generated from the point of the innermost error, and provide a
traceback of enclosing expressions and function calls.
</p>
<p>In the example above, the first line indicates that a variable named
&lsquo;<samp class="samp">x</samp>&rsquo; was found to be undefined near line 1 and column 24 of some
function or expression.  For errors occurring within functions, lines
are counted from the beginning of the file containing the function
definition.  For errors occurring outside of an enclosing function,
the line number indicates the input line number, which is usually displayed
in the primary prompt string.
</p>
<p>The second and third lines of the error message indicate that the error
occurred within the function <code class="code">f</code>.  If the function <code class="code">f</code> had been
called from within another function, for example, <code class="code">g</code>, the list of
errors would have ended with one more line:
</p>
<div class="example">
<pre class="example-preformatted">error:   g at line 1, column 17
</pre></div>

<p>These lists of function calls make it fairly easy to trace the
path your program took before the error occurred, and to correct the
error before trying again.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Executable-Octave-Programs.html">Executable Octave Programs</a>, Previous: <a href="Command-Line-Editing.html">Command Line Editing</a>, Up: <a href="Getting-Started.html">Getting Started</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>