annotate doc/interpreter/errors.texi @ 2679:79c851e2f0ee

[project @ 1997-02-14 04:32:00 by jwe]
author jwe
date Fri, 14 Feb 1997 04:33:35 +0000
parents
children 8c7955a8d49f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2679
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
1 @c Copyright (C) 1996, 1997 John W. Eaton
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
2 @c This is part of the Octave manual.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
3 @c For copying conditions, see the file gpl.texi.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
4
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
5 @node Error Handling, Input and Output, Functions and Scripts, Top
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
6 @chapter Error Handling
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
7
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
8 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
9 The @code{error} function formats the optional arguments under the
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
10 control of the template string @var{template} using the same rules as
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
11 the @code{printf} family of functions (@pxref{Formatted Output}).
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
12 The resulting message is prefixed by the string @samp{error: } and
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
13 printed on the @code{stderr} stream.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
14
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
15 Calling @code{error} also sets Octave's internal error state such that
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
16 control will return to the top level without evaluating any more
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
17 commands. This is useful for aborting from functions or scripts.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
18
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
19 If the error message does not end with a new line character, Octave will
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
20 print a traceback of all the function calls leading to the error. For
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
21 example, given the following function definitions:
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
22
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
23 @example
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
24 @group
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
25 function f () g () end
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
26 function g () h () end
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
27 function h () nargin == 1 || error ("nargin != 1"); end
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
28 @end group
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
29 @end example
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
30
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
31 @noindent
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
32 calling the function @code{f} will result in a list of messages that
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
33 can help you to quickly locate the exact location of the error:
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
34
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
35 @example
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
36 @group
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
37 f ()
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
38 error: nargin != 1
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
39 error: evaluating index expression near line 1, column 30
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
40 error: evaluating binary operator `||' near line 1, column 27
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
41 error: called from `h'
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
42 error: called from `g'
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
43 error: called from `f'
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
44 @end group
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
45 @end example
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
46
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
47 If the error message ends in a new line character, Octave will print the
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
48 message but will not display any traceback messages as it returns
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
49 control to the top level. For example, modifying the error message
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
50 in the previous example to end in a new line causes Octave to only print
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
51 a single message:
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
52
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
53 @example
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
54 @group
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
55 function h () nargin == 1 || error ("nargin != 1\n"); end
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
56 f ()
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
57 error: nargin != 1
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
58 @end group
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
59 @end example
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
60 @end deftypefn
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
61
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
62 @defvr {Built-in Variable} error_text
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
63 This variable contains the the text of error messages that would have
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
64 been printed in the body of the most recent @code{unwind_protect} or
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
65 @code{try} statement or the @var{try} part of the most recent call to
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
66 the @code{eval} function. Outside of the @code{unwind_protect} and
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
67 @code{try} statements or the @code{eval} function, or if no error has
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
68 ocurred within them, the value of @code{error_text} is guaranteed to be
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
69 the empty string.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
70
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
71 Note that the message does not include the first @samp{error: } prefix,
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
72 so that it may easily be passed to the @code{error} function without
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
73 additional processing@footnote{Yes, it's a kluge, but it seems to be a
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
74 reasonably useful one.}.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
75
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
76 @xref{The try Statement} and @ref{The unwind_protect Statement}.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
77 @end defvr
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
78
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
79 @defvr {Built-in Variable} beep_on_error
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
80 If the value of @code{beep_on_error} is nonzero, Octave will try
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
81 to ring your terminal's bell before printing an error message. The
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
82 default value is 0.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
83 @end defvr
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
84
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
85 @deftypefn {Built-in Function} {} warning (@var{msg})
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
86 Print the message @var{msg} prefixed by the string @samp{warning: }.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
87 @end deftypefn
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
88
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
89 @deftypefn {Built-in Function} {} usage (@var{msg})
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
90 Print the message @var{msg}, prefixed by the string @samp{usage: }, and
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
91 set Octave's internal error state such that control will return to the
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
92 top level without evaluating any more commands. This is useful for
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
93 aborting from functions.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
94
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
95 After @code{usage} is evaluated, Octave will print a traceback of all
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
96 the function calls leading to the usage message.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
97 @end deftypefn
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
98
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
99 The following pair of functions are of limited usefulness, and may be
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
100 removed from future versions of Octave.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
101
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
102 @deftypefn {Function File} {} perror (@var{name}, @var{num})
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
103 Print the error message for function @var{name} corresponding to the
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
104 error number @var{num}. This function is intended to be used to print
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
105 useful error messages for those functions that return numeric error
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
106 codes.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
107 @end deftypefn
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
108
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
109 @deftypefn {Function File} {} strerror (@var{name}, @var{num})
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
110 Return the text of an error message for function @var{name}
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
111 corresponding to the error number @var{num}. This function is intended
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
112 to be used to print useful error messages for those functions that
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
113 return numeric error codes.
79c851e2f0ee [project @ 1997-02-14 04:32:00 by jwe]
jwe
parents:
diff changeset
114 @end deftypefn