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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Errors (GNU Octave (version 6.2.0))</title>
<meta name="description" content="Errors (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Errors (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<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="Diary-and-Echo-Commands.html" rel="prev" title="Diary and Echo Commands">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<span id="Errors"></span><div class="header">
<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> [<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>
<span id="How-Octave-Reports-Errors"></span><h3 class="section">2.5 How Octave Reports Errors</h3>
<span id="index-error-messages"></span>
<span id="index-messages_002c-error"></span>
<p>Octave reports two kinds of errors for invalid programs.
</p>
<p>A <em>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">octave:13> function y = f (x) y = x***2; endfunction
</pre></div>
<p>Octave will respond immediately with a message like this:
</p>
<div class="example">
<pre class="example">parse error:
syntax error
>>> function y = f (x) y = x***2; endfunction
^
</pre></div>
<p>For most parse errors, Octave uses a caret (‘<samp>^</samp>’) 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
exponentiation (<code>**</code>) was misspelled. It marked the error at the
third ‘<samp>*</samp>’ because the code leading up to this was correct but the final
‘<samp>*</samp>’ was not understood.
</p>
<p>Another class of error message occurs at evaluation time. These
errors are called <em>run-time errors</em>, or sometimes
<em>evaluation errors</em>, because they occur when your program is being
<em>run</em>, or <em>evaluated</em>. For example, if after correcting the
mistake in the previous function definition, you type
</p>
<div class="example">
<pre class="example">octave:13> f ()
</pre></div>
<p>Octave will respond with
</p>
<div class="example">
<pre class="example">error: `x' undefined near line 1 column 24
error: called from:
error: f at line 1, column 22
</pre></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
‘<samp>x</samp>’ 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>f</code>. If the function <code>f</code> had been
called from within another function, for example, <code>g</code>, the list of
errors would have ended with one more line:
</p>
<div class="example">
<pre class="example">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>
<hr>
<div class="header">
<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> [<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>
|