Mercurial > hg > octave-nkf
annotate src/error.cc @ 10160:cd96d29c5efa
remove Emacs local-variable settings from source files in src directory
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Jan 2010 20:39:26 -0500 |
parents | 2cd940306a06 |
children | 57a59eae83cc |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8920 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
1343 | 28 #include <cstdarg> |
1633 | 29 #include <cstring> |
1343 | 30 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 #include <iostream> |
5765 | 32 #include <sstream> |
1728 | 33 #include <string> |
34 | |
1352 | 35 #include "defun.h" |
1 | 36 #include "error.h" |
3707 | 37 #include "input.h" |
1742 | 38 #include "pager.h" |
1352 | 39 #include "oct-obj.h" |
5567 | 40 #include "oct-map.h" |
1352 | 41 #include "utils.h" |
2370 | 42 #include "ov.h" |
3707 | 43 #include "ov-usr-fcn.h" |
44 #include "pt-pr-code.h" | |
45 #include "pt-stmt.h" | |
46 #include "toplev.h" | |
47 #include "unwind-prot.h" | |
2370 | 48 #include "variables.h" |
1 | 49 |
2174 | 50 // TRUE means that Octave will try to beep obnoxiously before printing |
51 // error messages. | |
5794 | 52 static bool Vbeep_on_error = false; |
2174 | 53 |
3707 | 54 // TRUE means that Octave will try to enter the debugger when an error |
55 // is encountered. This will also inhibit printing of the normal | |
56 // traceback message (you will only see the top-level error message). | |
7353 | 57 bool Vdebug_on_error = false; |
3707 | 58 |
59 // TRUE means that Octave will try to enter the debugger when a warning | |
60 // is encountered. | |
7353 | 61 bool Vdebug_on_warning = false; |
3707 | 62 |
5567 | 63 // TRUE means that Octave will try to display a stack trace when a |
64 // warning is encountered. | |
65 static bool Vbacktrace_on_warning = false; | |
66 | |
67 // TRUE means that Octave will print a verbose warning. Currently unused. | |
68 static bool Vverbose_warning; | |
69 | |
5582 | 70 // TRUE means that Octave will print no warnings, but lastwarn will be |
71 //updated | |
72 static bool Vquiet_warning = false; | |
73 | |
5567 | 74 // A structure containing (most of) the current state of warnings. |
75 static Octave_map warning_options; | |
76 | |
3935 | 77 // The text of the last error message. |
78 static std::string Vlast_error_message; | |
79 | |
3934 | 80 // The text of the last warning message. |
81 static std::string Vlast_warning_message; | |
82 | |
5567 | 83 // The last warning message id. |
84 static std::string Vlast_warning_id; | |
3934 | 85 |
5567 | 86 // The last error message id. |
87 static std::string Vlast_error_id; | |
3934 | 88 |
6361 | 89 // The last file in which an error occured |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
90 static Octave_map Vlast_error_stack; |
6361 | 91 |
143 | 92 // Current error state. |
3935 | 93 // |
94 // Valid values: | |
95 // | |
96 // -2: an error has occurred, but don't print any messages. | |
97 // -1: an error has occurred, we are printing a traceback | |
98 // 0: no error | |
99 // 1: an error has occurred | |
100 // | |
672 | 101 int error_state = 0; |
102 | |
3489 | 103 // Current warning state. |
3935 | 104 // |
105 // Valid values: | |
106 // | |
107 // 0: no warning | |
108 // 1: a warning has occurred | |
109 // | |
3489 | 110 int warning_state = 0; |
111 | |
1489 | 112 // Tell the error handler whether to print messages, or just store |
113 // them for later. Used for handling errors in eval() and | |
114 // the `unwind_protect' statement. | |
4699 | 115 int buffer_error_messages = 0; |
1489 | 116 |
3815 | 117 // TRUE means error messages are turned off. |
118 bool discard_error_messages = false; | |
119 | |
4452 | 120 // TRUE means warning messages are turned off. |
121 bool discard_warning_messages = false; | |
122 | |
3811 | 123 // The message buffer. |
5765 | 124 static std::ostringstream *error_message_buffer = 0; |
143 | 125 |
4318 | 126 void |
127 reset_error_handler (void) | |
128 { | |
129 error_state = 0; | |
130 warning_state = 0; | |
4699 | 131 buffer_error_messages = 0; |
4318 | 132 discard_error_messages = false; |
133 } | |
134 | |
5567 | 135 static void |
5794 | 136 initialize_warning_options (const std::string& state) |
5567 | 137 { |
138 warning_options.clear (); | |
139 | |
140 warning_options.assign ("identifier", "all"); | |
141 warning_options.assign ("state", state); | |
142 } | |
143 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
144 static Octave_map |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
145 initialize_last_error_stack (void) |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
146 { |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
147 static bool initialized = false; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
148 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
149 static string_vector sv (4); |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
150 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
151 if (! initialized) |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
152 { |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
153 sv[0] = "file"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
154 sv[1] = "name"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
155 sv[2] = "line"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
156 sv[3] = "column"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
157 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
158 initialized = true; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
159 } |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
160 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
161 return Octave_map (dim_vector (0, 1), sv); |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
162 } |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
163 |
3491 | 164 // Warning messages are never buffered. |
165 | |
166 static void | |
5567 | 167 vwarning (const char *name, const char *id, const char *fmt, va_list args) |
3491 | 168 { |
4452 | 169 if (discard_warning_messages) |
170 return; | |
171 | |
3491 | 172 flush_octave_stdout (); |
173 | |
5765 | 174 std::ostringstream output_buf; |
3491 | 175 |
176 if (name) | |
3761 | 177 output_buf << name << ": "; |
178 | |
179 octave_vformat (output_buf, fmt, args); | |
180 | |
5765 | 181 output_buf << std::endl; |
3491 | 182 |
5775 | 183 // FIXME -- we really want to capture the message before it |
3935 | 184 // has all the formatting goop attached to it. We probably also |
185 // want just the message, not the traceback information. | |
186 | |
5765 | 187 std::string msg_string = output_buf.str (); |
3934 | 188 |
3935 | 189 if (! warning_state) |
190 { | |
191 // This is the first warning in a possible series. | |
5567 | 192 |
193 Vlast_warning_id = id; | |
3935 | 194 Vlast_warning_message = msg_string; |
195 } | |
3934 | 196 |
5582 | 197 if (! Vquiet_warning) |
198 { | |
199 octave_diary << msg_string; | |
3935 | 200 |
5582 | 201 std::cerr << msg_string; |
202 } | |
3491 | 203 } |
204 | |
1 | 205 static void |
4732 | 206 verror (bool save_last_error, std::ostream& os, |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
207 const char *name, const char *id, const char *fmt, va_list args, |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
208 bool with_cfn = false) |
1 | 209 { |
3815 | 210 if (discard_error_messages) |
211 return; | |
212 | |
3585 | 213 if (! buffer_error_messages) |
214 flush_octave_stdout (); | |
914 | 215 |
5775 | 216 // FIXME -- we really want to capture the message before it |
3935 | 217 // has all the formatting goop attached to it. We probably also |
218 // want just the message, not the traceback information. | |
219 | |
7877 | 220 std::ostringstream output_buf; |
221 | |
222 octave_vformat (output_buf, fmt, args); | |
223 | |
224 std::string base_msg = output_buf.str (); | |
225 | |
226 bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; | |
227 | |
228 std::string msg_string; | |
229 | |
230 if (to_beep_or_not_to_beep_p) | |
231 msg_string = "\a"; | |
232 | |
233 if (name) | |
234 msg_string += std::string (name) + ": "; | |
235 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
236 // If with_fcn is specified, we'll attempt to prefix the message with the name |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
237 // of the current executing function. But we'll do so only if: |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
238 // 1. the name is not empty (anonymous function) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
239 // 2. it is not already there (including the following colon) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
240 if (with_cfn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
241 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
242 octave_function *curfcn = octave_call_stack::current (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
243 if (curfcn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
244 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
245 std::string cfn = curfcn->name (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
246 if (! cfn.empty ()) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
247 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
248 cfn += ':'; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
249 if (cfn.length () > base_msg.length () |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
250 || base_msg.compare (0, cfn.length (), cfn) != 0) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
251 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
252 msg_string += cfn + ' '; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
253 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
254 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
255 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
256 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
257 |
7880 | 258 msg_string += base_msg + "\n"; |
3935 | 259 |
4731 | 260 if (! error_state && save_last_error) |
3935 | 261 { |
262 // This is the first error in a possible series. | |
5567 | 263 |
264 Vlast_error_id = id; | |
7877 | 265 Vlast_error_message = base_msg; |
6361 | 266 |
7877 | 267 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
6361 | 268 |
7877 | 269 if (fcn) |
270 { | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
271 octave_idx_type curr_frame = -1; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
272 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
273 Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame); |
6361 | 274 } |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
275 else |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
276 Vlast_error_stack = initialize_last_error_stack (); |
3935 | 277 } |
278 | |
1489 | 279 if (buffer_error_messages) |
280 { | |
7882 | 281 if (error_message_buffer) |
282 msg_string = "error: " + msg_string; | |
283 else | |
7880 | 284 error_message_buffer = new std::ostringstream (); |
1489 | 285 |
7880 | 286 *error_message_buffer << msg_string; |
1489 | 287 } |
288 else | |
289 { | |
3935 | 290 octave_diary << msg_string; |
4732 | 291 os << msg_string; |
1489 | 292 } |
1 | 293 } |
294 | |
1266 | 295 // Note that we don't actually print any message if the error string |
296 // is just "" or "\n". This allows error ("") and error ("\n") to | |
297 // just set the error state. | |
298 | |
1005 | 299 static void |
5567 | 300 error_1 (std::ostream& os, const char *name, const char *id, |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
301 const char *fmt, va_list args, bool with_cfn = false) |
1005 | 302 { |
303 if (error_state != -2) | |
304 { | |
1489 | 305 if (fmt) |
1005 | 306 { |
1489 | 307 if (*fmt) |
1005 | 308 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
309 size_t len = strlen (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
310 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
311 if (len > 0) |
1266 | 312 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
313 if (fmt[len - 1] == '\n') |
1266 | 314 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
315 if (len > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
316 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
317 char *tmp_fmt = strsave (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
318 tmp_fmt[len - 1] = '\0'; |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
319 verror (true, os, name, id, tmp_fmt, args, with_cfn); |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
320 delete [] tmp_fmt; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
321 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
322 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
323 error_state = -2; |
1489 | 324 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
325 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
326 { |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
327 verror (true, os, name, id, fmt, args, with_cfn); |
1423 | 328 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
329 if (! error_state) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
330 error_state = 1; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
331 } |
1266 | 332 } |
1005 | 333 } |
334 } | |
1489 | 335 else |
336 panic ("error_1: invalid format"); | |
1005 | 337 } |
338 } | |
339 | |
1 | 340 void |
6338 | 341 vmessage (const char *name, const char *fmt, va_list args) |
342 { | |
343 verror (false, std::cerr, name, "", fmt, args); | |
344 } | |
345 | |
346 void | |
1 | 347 message (const char *name, const char *fmt, ...) |
348 { | |
349 va_list args; | |
350 va_start (args, fmt); | |
6338 | 351 vmessage (name, fmt, args); |
1 | 352 va_end (args); |
353 } | |
354 | |
355 void | |
6338 | 356 vmessage_with_id (const char *name, const char *id, const char *fmt, |
357 va_list args) | |
358 { | |
359 verror (false, std::cerr, name, id, fmt, args); | |
360 } | |
361 | |
362 void | |
5567 | 363 message_with_id (const char *name, const char *id, const char *fmt, ...) |
364 { | |
365 va_list args; | |
366 va_start (args, fmt); | |
6338 | 367 vmessage_with_id (name, id, fmt, args); |
5567 | 368 va_end (args); |
369 } | |
370 | |
371 void | |
372 usage_1 (const char *id, const char *fmt, va_list args) | |
373 { | |
374 verror (true, std::cerr, "usage", id, fmt, args); | |
375 error_state = -1; | |
376 } | |
377 | |
378 void | |
6338 | 379 vusage (const char *fmt, va_list args) |
380 { | |
381 usage_1 ("", fmt, args); | |
382 } | |
383 | |
384 void | |
1 | 385 usage (const char *fmt, ...) |
386 { | |
387 va_list args; | |
388 va_start (args, fmt); | |
6338 | 389 vusage (fmt, args); |
5567 | 390 va_end (args); |
391 } | |
392 | |
393 void | |
6338 | 394 vusage_with_id (const char *id, const char *fmt, va_list args) |
395 { | |
396 usage_1 (id, fmt, args); | |
397 } | |
398 | |
399 void | |
5567 | 400 usage_with_id (const char *id, const char *fmt, ...) |
401 { | |
402 va_list args; | |
403 va_start (args, fmt); | |
6338 | 404 vusage_with_id (id, fmt, args); |
1 | 405 va_end (args); |
406 } | |
407 | |
3707 | 408 static void |
3719 | 409 pr_where_2 (const char *fmt, va_list args) |
410 { | |
411 if (fmt) | |
412 { | |
413 if (*fmt) | |
414 { | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
415 size_t len = strlen (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
416 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
417 if (len > 0) |
3719 | 418 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
419 if (fmt[len - 1] == '\n') |
3719 | 420 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
421 if (len > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
422 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
423 char *tmp_fmt = strsave (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
424 tmp_fmt[len - 1] = '\0'; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
425 verror (false, std::cerr, 0, "", tmp_fmt, args); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
426 delete [] tmp_fmt; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
427 } |
3719 | 428 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
429 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
430 verror (false, std::cerr, 0, "", fmt, args); |
3719 | 431 } |
432 } | |
433 } | |
434 else | |
435 panic ("pr_where_2: invalid format"); | |
436 } | |
437 | |
438 static void | |
3707 | 439 pr_where_1 (const char *fmt, ...) |
440 { | |
441 va_list args; | |
442 va_start (args, fmt); | |
3719 | 443 pr_where_2 (fmt, args); |
3707 | 444 va_end (args); |
445 } | |
446 | |
447 static void | |
8973 | 448 pr_where (const char *who) |
3707 | 449 { |
8973 | 450 octave_idx_type curr_frame = -1; |
3707 | 451 |
8973 | 452 Octave_map stk = octave_call_stack::backtrace (0, curr_frame); |
4976 | 453 |
8973 | 454 octave_idx_type nframes_to_display = stk.numel (); |
4976 | 455 |
8973 | 456 if (nframes_to_display > 0) |
457 { | |
458 pr_where_1 ("%s: called from\n", who); | |
3708 | 459 |
8973 | 460 Cell names = stk.contents ("name"); |
461 Cell lines = stk.contents ("line"); | |
462 Cell columns = stk.contents ("column"); | |
3707 | 463 |
8973 | 464 for (octave_idx_type i = 0; i < nframes_to_display; i++) |
4976 | 465 { |
8973 | 466 octave_value name = names(i); |
467 octave_value line = lines(i); | |
468 octave_value column = columns(i); | |
3707 | 469 |
8973 | 470 std::string nm = name.string_value (); |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7353
diff
changeset
|
471 |
8973 | 472 pr_where_1 (" %s at line %d column %d\n", nm.c_str (), |
473 line.int_value (), column.int_value ()); | |
4719 | 474 } |
3707 | 475 } |
476 } | |
477 | |
6000 | 478 static void |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
479 error_2 (const char *id, const char *fmt, va_list args, bool with_cfn = false) |
6000 | 480 { |
481 int init_state = error_state; | |
482 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
483 error_1 (std::cerr, "error", id, fmt, args, with_cfn); |
6000 | 484 |
485 if ((interactive || forced_interactive) | |
486 && Vdebug_on_error && init_state == 0 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
487 && octave_call_stack::caller_user_code ()) |
6000 | 488 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
489 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
490 frame.protect_var (Vdebug_on_error); |
6000 | 491 Vdebug_on_error = false; |
492 | |
8973 | 493 error_state = 0; |
6000 | 494 |
8973 | 495 pr_where ("error"); |
6000 | 496 |
497 do_keyboard (octave_value_list ()); | |
498 } | |
499 } | |
500 | |
501 void | |
6338 | 502 verror (const char *fmt, va_list args) |
503 { | |
504 error_2 ("", fmt, args); | |
505 } | |
506 | |
507 void | |
6000 | 508 error (const char *fmt, ...) |
509 { | |
510 va_list args; | |
511 va_start (args, fmt); | |
6338 | 512 verror (fmt, args); |
6000 | 513 va_end (args); |
514 } | |
515 | |
516 void | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
517 verror_with_cfn (const char *fmt, va_list args) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
518 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
519 error_2 ("", fmt, args, true); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
520 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
521 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
522 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
523 error_with_cfn (const char *fmt, ...) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
524 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
525 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
526 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
527 verror_with_cfn (fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
528 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
529 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
530 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
531 void |
6338 | 532 verror_with_id (const char *id, const char *fmt, va_list args) |
533 { | |
534 error_2 (id, fmt, args); | |
535 } | |
536 | |
537 void | |
6000 | 538 error_with_id (const char *id, const char *fmt, ...) |
539 { | |
540 va_list args; | |
541 va_start (args, fmt); | |
6338 | 542 verror_with_id (id, fmt, args); |
6000 | 543 va_end (args); |
544 } | |
545 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
546 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
547 verror_with_id_cfn (const char *id, const char *fmt, va_list args) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
548 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
549 error_2 (id, fmt, args, true); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
550 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
551 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
552 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
553 error_with_id_cfn (const char *id, const char *fmt, ...) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
554 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
555 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
556 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
557 verror_with_id_cfn (id, fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
558 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
559 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
560 |
5567 | 561 static int |
562 check_state (const std::string& state) | |
563 { | |
564 // -1: not found | |
565 // 0: found, "off" | |
566 // 1: found, "on" | |
567 // 2: found, "error" | |
568 | |
569 if (state == "off") | |
570 return 0; | |
571 else if (state == "on") | |
572 return 1; | |
573 else if (state == "error") | |
574 return 2; | |
575 else | |
576 return -1; | |
577 } | |
578 | |
579 // For given warning ID, return 0 if warnings are disabled, 1 if | |
580 // enabled, and 2 if this ID should be an error instead of a warning. | |
581 | |
5781 | 582 int |
5567 | 583 warning_enabled (const std::string& id) |
1 | 584 { |
5567 | 585 int retval = 0; |
586 | |
587 int all_state = -1; | |
588 int id_state = -1; | |
589 | |
590 octave_idx_type nel = warning_options.numel (); | |
591 | |
592 if (nel > 0) | |
593 { | |
594 Cell identifier = warning_options.contents ("identifier"); | |
595 Cell state = warning_options.contents ("state"); | |
596 | |
597 bool all_found = false; | |
598 bool id_found = false; | |
599 | |
600 for (octave_idx_type i = 0; i < nel; i++) | |
601 { | |
602 octave_value ov = identifier(i); | |
603 std::string ovs = ov.string_value (); | |
604 | |
605 if (! all_found && ovs == "all") | |
606 { | |
607 all_state = check_state (state(i).string_value ()); | |
608 | |
609 if (all_state >= 0) | |
610 all_found = true; | |
611 } | |
612 | |
613 if (! id_found && ovs == id) | |
614 { | |
615 id_state = check_state (state(i).string_value ()); | |
616 | |
617 if (id_state >= 0) | |
618 id_found = true; | |
619 } | |
620 | |
621 if (all_found && id_found) | |
622 break; | |
623 } | |
624 } | |
625 | |
626 if (all_state == -1) | |
627 panic_impossible (); | |
628 | |
629 if (all_state == 0) | |
630 { | |
631 if (id_state >= 0) | |
632 retval = id_state; | |
633 } | |
634 else if (all_state == 1) | |
635 { | |
636 if (id_state == 0 || id_state == 2) | |
637 retval = id_state; | |
638 else | |
639 retval = all_state; | |
640 } | |
641 else if (all_state == 2) | |
7206 | 642 { |
643 if (id_state == 0) | |
644 retval= id_state; | |
645 else | |
646 retval = all_state; | |
647 } | |
5567 | 648 |
649 return retval; | |
650 } | |
651 | |
652 static void | |
653 warning_1 (const char *id, const char *fmt, va_list args) | |
654 { | |
655 int warn_opt = warning_enabled (id); | |
656 | |
657 if (warn_opt == 2) | |
658 { | |
659 // Handle this warning as an error. | |
660 | |
5998 | 661 error_2 (id, fmt, args); |
5567 | 662 } |
663 else if (warn_opt == 1) | |
3934 | 664 { |
8973 | 665 vwarning ("warning", id, fmt, args); |
666 | |
667 if (! symbol_table::at_top_level () | |
5567 | 668 && Vbacktrace_on_warning |
4452 | 669 && ! warning_state |
670 && ! discard_warning_messages) | |
8973 | 671 pr_where ("warning"); |
3707 | 672 |
3935 | 673 warning_state = 1; |
674 | |
3934 | 675 if ((interactive || forced_interactive) |
5743 | 676 && Vdebug_on_warning |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
677 && octave_call_stack::caller_user_code ()) |
3934 | 678 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
679 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
680 frame.protect_var (Vdebug_on_warning); |
3934 | 681 Vdebug_on_warning = false; |
3707 | 682 |
3934 | 683 do_keyboard (octave_value_list ()); |
684 } | |
3707 | 685 } |
1 | 686 } |
687 | |
688 void | |
6338 | 689 vwarning (const char *fmt, va_list args) |
690 { | |
691 warning_1 ("", fmt, args); | |
692 } | |
693 | |
694 void | |
5567 | 695 warning (const char *fmt, ...) |
696 { | |
697 va_list args; | |
698 va_start (args, fmt); | |
6338 | 699 vwarning (fmt, args); |
5567 | 700 va_end (args); |
701 } | |
702 | |
703 void | |
6338 | 704 vwarning_with_id (const char *id, const char *fmt, va_list args) |
705 { | |
706 warning_1 (id, fmt, args); | |
707 } | |
708 | |
709 void | |
5567 | 710 warning_with_id (const char *id, const char *fmt, ...) |
711 { | |
712 va_list args; | |
713 va_start (args, fmt); | |
6338 | 714 vwarning_with_id (id, fmt, args); |
5567 | 715 va_end (args); |
716 } | |
717 | |
718 void | |
6338 | 719 vparse_error (const char *fmt, va_list args) |
720 { | |
721 error_1 (std::cerr, 0, "", fmt, args); | |
722 } | |
723 | |
724 void | |
1005 | 725 parse_error (const char *fmt, ...) |
726 { | |
727 va_list args; | |
728 va_start (args, fmt); | |
6338 | 729 vparse_error (fmt, args); |
5567 | 730 va_end (args); |
731 } | |
732 | |
733 void | |
6338 | 734 vparse_error_with_id (const char *id, const char *fmt, va_list args) |
735 { | |
736 error_1 (std::cerr, 0, id, fmt, args); | |
737 } | |
738 | |
739 void | |
5567 | 740 parse_error_with_id (const char *id, const char *fmt, ...) |
741 { | |
742 va_list args; | |
743 va_start (args, fmt); | |
6338 | 744 vparse_error_with_id (id, fmt, args); |
1 | 745 va_end (args); |
746 } | |
747 | |
189 | 748 void |
6361 | 749 rethrow_error (const char *id, const char *fmt, ...) |
750 { | |
751 va_list args; | |
752 va_start (args, fmt); | |
6640 | 753 error_1 (std::cerr, 0, id, fmt, args); |
6361 | 754 va_end (args); |
755 } | |
756 | |
757 void | |
1 | 758 panic (const char *fmt, ...) |
759 { | |
760 va_list args; | |
761 va_start (args, fmt); | |
4699 | 762 buffer_error_messages = 0; |
3815 | 763 discard_error_messages = false; |
5567 | 764 verror (false, std::cerr, "panic", "", fmt, args); |
1 | 765 va_end (args); |
766 abort (); | |
767 } | |
768 | |
4732 | 769 static void |
770 defun_usage_message_1 (const char *fmt, ...) | |
771 { | |
772 va_list args; | |
773 va_start (args, fmt); | |
5567 | 774 error_1 (octave_stdout, 0, "", fmt, args); |
4732 | 775 va_end (args); |
776 } | |
777 | |
778 void | |
779 defun_usage_message (const std::string& msg) | |
780 { | |
781 defun_usage_message_1 ("%s", msg.c_str ()); | |
782 } | |
783 | |
5567 | 784 typedef void (*error_fun)(const char *, const char *, ...); |
1489 | 785 |
2086 | 786 extern octave_value_list Fsprintf (const octave_value_list&, int); |
1489 | 787 |
3934 | 788 static std::string |
5567 | 789 handle_message (error_fun f, const char *id, const char *msg, |
790 const octave_value_list& args) | |
528 | 791 { |
3934 | 792 std::string retval; |
528 | 793 |
3523 | 794 std::string tstr; |
1728 | 795 |
528 | 796 int nargin = args.length (); |
797 | |
2745 | 798 if (nargin > 0) |
528 | 799 { |
3066 | 800 octave_value arg; |
801 | |
802 if (nargin > 1) | |
803 { | |
804 octave_value_list tmp = Fsprintf (args, 1); | |
805 arg = tmp(0); | |
806 } | |
807 else | |
808 arg = args(0); | |
2745 | 809 |
810 if (arg.is_defined ()) | |
528 | 811 { |
2745 | 812 if (arg.is_string ()) |
813 { | |
814 tstr = arg.string_value (); | |
815 msg = tstr.c_str (); | |
816 | |
817 if (! msg) | |
818 return retval; | |
819 } | |
820 else if (arg.is_empty ()) | |
528 | 821 return retval; |
822 } | |
823 } | |
824 | |
1489 | 825 // Ugh. |
826 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
827 size_t len = strlen (msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
828 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
829 if (len > 0) |
1489 | 830 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
831 if (msg[len - 1] == '\n') |
1489 | 832 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
833 if (len > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
834 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
835 char *tmp_msg = strsave (msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
836 tmp_msg[len - 1] = '\0'; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
837 f (id, "%s\n", tmp_msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
838 retval = tmp_msg; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
839 delete [] tmp_msg; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
840 } |
1489 | 841 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
842 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
843 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
844 f (id, "%s", msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
845 retval = msg; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
846 } |
3934 | 847 } |
528 | 848 |
849 return retval; | |
850 } | |
851 | |
6361 | 852 DEFUN (rethrow, args, , |
853 "-*- texinfo -*-\n\ | |
854 @deftypefn {Built-in Function} {} rethrow (@var{err})\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
855 Reissues a previous error as defined by @var{err}. @var{err} is a structure\n\ |
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
856 that must contain at least the 'message' and 'identifier' fields. @var{err}\n\ |
6361 | 857 can also contain a field 'stack' that gives information on the assumed\n\ |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
858 location of the error. Typically @var{err} is returned from\n\ |
6361 | 859 @code{lasterror}.\n\ |
860 @seealso{lasterror, lasterr, error}\n\ | |
861 @end deftypefn") | |
862 { | |
863 octave_value retval; | |
864 int nargin = args.length(); | |
865 | |
866 if (nargin != 1) | |
6959 | 867 print_usage (); |
6361 | 868 else |
869 { | |
6483 | 870 Octave_map err = args(0).map_value (); |
6361 | 871 |
6483 | 872 if (! error_state) |
6361 | 873 { |
6483 | 874 if (err.contains ("message") && err.contains ("identifier")) |
6361 | 875 { |
6483 | 876 std::string msg = err.contents("message")(0).string_value (); |
877 std::string id = err.contents("identifier")(0).string_value (); | |
6361 | 878 int len = msg.length(); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
879 |
6361 | 880 std::string file; |
881 std::string nm; | |
882 int l = -1; | |
883 int c = -1; | |
884 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
885 Octave_map err_stack = initialize_last_error_stack (); |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
886 |
6483 | 887 if (err.contains ("stack")) |
6361 | 888 { |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
889 err_stack = err.contents("stack")(0).map_value (); |
6483 | 890 |
6640 | 891 if (err_stack.numel () > 0) |
892 { | |
893 if (err_stack.contains ("file")) | |
894 file = err_stack.contents("file")(0).string_value (); | |
6483 | 895 |
6640 | 896 if (err_stack.contains ("name")) |
897 nm = err_stack.contents("name")(0).string_value (); | |
6483 | 898 |
6640 | 899 if (err_stack.contains ("line")) |
900 l = err_stack.contents("line")(0).nint_value (); | |
901 | |
902 if (err_stack.contains ("column")) | |
903 c = err_stack.contents("column")(0).nint_value (); | |
904 } | |
6361 | 905 } |
906 | |
907 // Ugh. | |
6483 | 908 char *tmp_msg = strsave (msg.c_str ()); |
6361 | 909 if (tmp_msg[len-1] == '\n') |
910 { | |
911 if (len > 1) | |
912 { | |
913 tmp_msg[len - 1] = '\0'; | |
6483 | 914 rethrow_error (id.c_str (), "%s\n", tmp_msg); |
6361 | 915 } |
916 } | |
917 else | |
6483 | 918 rethrow_error (id.c_str (), "%s", tmp_msg); |
6361 | 919 delete [] tmp_msg; |
920 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
921 // FIXME -- is this the right thing to do for |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
922 // Vlast_error_stack? Should it be saved and restored |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
923 // with unwind_protect? |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
924 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
925 Vlast_error_stack = err_stack; |
6361 | 926 |
6483 | 927 if (err.contains ("stack")) |
6361 | 928 { |
929 if (file.empty ()) | |
930 { | |
931 if (nm.empty ()) | |
932 { | |
933 if (l > 0) | |
6483 | 934 { |
935 if (c > 0) | |
936 pr_where_1 ("error: near line %d, column %d", | |
937 l, c); | |
938 else | |
939 pr_where_1 ("error: near line %d", l); | |
940 } | |
6361 | 941 } |
942 else | |
943 { | |
944 if (l > 0) | |
6483 | 945 { |
946 if (c > 0) | |
947 pr_where_1 ("error: called from `%s' near line %d, column %d", | |
948 nm.c_str (), l, c); | |
949 else | |
950 pr_where_1 ("error: called from `%d' near line %d", nm.c_str (), l); | |
951 } | |
6361 | 952 } |
953 } | |
954 else | |
955 { | |
956 if (nm.empty ()) | |
957 { | |
958 if (l > 0) | |
6483 | 959 { |
960 if (c > 0) | |
961 pr_where_1 ("error: in file %s near line %d, column %d", | |
962 file.c_str (), l, c); | |
963 else | |
964 pr_where_1 ("error: in file %s near line %d", file.c_str (), l); | |
965 } | |
6361 | 966 } |
967 else | |
968 { | |
969 if (l > 0) | |
6483 | 970 { |
971 if (c > 0) | |
972 pr_where_1 ("error: called from `%s' in file %s near line %d, column %d", | |
973 nm.c_str (), file.c_str (), l, c); | |
974 else | |
975 pr_where_1 ("error: called from `%d' in file %s near line %d", nm.c_str (), file.c_str (), l); | |
976 } | |
6361 | 977 } |
978 } | |
979 } | |
980 } | |
981 else | |
982 error ("rethrow: structure must contain the fields 'message and 'identifier'"); | |
983 } | |
984 } | |
985 return retval; | |
986 } | |
987 | |
1957 | 988 DEFUN (error, args, , |
3373 | 989 "-*- texinfo -*-\n\ |
990 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\ | |
7252 | 991 @deftypefnx {Built-in Function} {} error (@var{id}, @var{template}, @dots{})\n\ |
5781 | 992 Format the optional arguments under the control of the template string\n\ |
993 @var{template} using the same rules as the @code{printf} family of\n\ | |
994 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
995 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
996 string @samp{error: }.\n\ | |
3373 | 997 \n\ |
998 Calling @code{error} also sets Octave's internal error state such that\n\ | |
999 control will return to the top level without evaluating any more\n\ | |
1000 commands. This is useful for aborting from functions or scripts.\n\ | |
897 | 1001 \n\ |
3373 | 1002 If the error message does not end with a new line character, Octave will\n\ |
1003 print a traceback of all the function calls leading to the error. For\n\ | |
1004 example, given the following function definitions:\n\ | |
1005 \n\ | |
1006 @example\n\ | |
1007 @group\n\ | |
6671 | 1008 function f () g (); end\n\ |
1009 function g () h (); end\n\ | |
3373 | 1010 function h () nargin == 1 || error (\"nargin != 1\"); end\n\ |
1011 @end group\n\ | |
1012 @end example\n\ | |
1489 | 1013 \n\ |
3373 | 1014 @noindent\n\ |
1015 calling the function @code{f} will result in a list of messages that\n\ | |
1016 can help you to quickly locate the exact location of the error:\n\ | |
1489 | 1017 \n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1018 @example\n\ |
3373 | 1019 @group\n\ |
1020 f ()\n\ | |
1021 error: nargin != 1\n\ | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1022 error: called from:\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1023 error: error at line -1, column -1\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1024 error: h at line 1, column 27\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1025 error: g at line 1, column 15\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1026 error: f at line 1, column 15\n\ |
3373 | 1027 @end group\n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1028 @end example\n\ |
3373 | 1029 \n\ |
1030 If the error message ends in a new line character, Octave will print the\n\ | |
1031 message but will not display any traceback messages as it returns\n\ | |
1032 control to the top level. For example, modifying the error message\n\ | |
1033 in the previous example to end in a new line causes Octave to only print\n\ | |
1034 a single message:\n\ | |
1035 \n\ | |
1036 @example\n\ | |
1037 @group\n\ | |
1038 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\ | |
1039 f ()\n\ | |
1040 error: nargin != 1\n\ | |
1041 @end group\n\ | |
1042 @end example\n\ | |
1043 @end deftypefn") | |
897 | 1044 { |
7252 | 1045 octave_value retval; |
1046 | |
1047 int nargin = args.length (); | |
1048 | |
1049 octave_value_list nargs = args; | |
1050 | |
1051 std::string id; | |
1052 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1053 if (nargin == 0) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1054 print_usage (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1055 else |
7252 | 1056 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1057 if (nargin > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1058 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1059 std::string arg1 = args(0).string_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1060 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1061 if (! error_state) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1062 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1063 if (arg1.find ('%') == std::string::npos) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1064 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1065 id = arg1; |
5567 | 1066 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1067 nargs.resize (nargin-1); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1068 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1069 for (int i = 1; i < nargin; i++) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1070 nargs(i-1) = args(i); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1071 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1072 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1073 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1074 return retval; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1075 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1076 else if (nargin == 1 && args(0).is_map ()) |
7252 | 1077 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1078 octave_value_list tmp; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1079 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1080 Octave_map m = args(0).map_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1081 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1082 if (m.numel () == 1) |
7252 | 1083 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1084 if (m.contains ("message")) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1085 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1086 Cell c = m.contents ("message"); |
7252 | 1087 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1088 if (! c.is_empty () && c(0).is_string ()) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1089 nargs(0) = c(0).string_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1090 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1091 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1092 if (m.contains ("identifier")) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1093 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1094 Cell c = m.contents ("identifier"); |
7252 | 1095 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1096 if (! c.is_empty () && c(0).is_string ()) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1097 id = c(0).string_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1098 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1099 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1100 // FIXME -- also need to handle "stack" field in error |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1101 // structure, but that will require some more significant |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1102 // surgery on handle_message, error_with_id, etc. |
7252 | 1103 } |
1104 } | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1105 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1106 handle_message (error_with_id, id.c_str (), "unspecified error", nargs); |
7252 | 1107 } |
1108 | |
3934 | 1109 return retval; |
1489 | 1110 } |
897 | 1111 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
1112 DEFUN (warning, args, nargout, |
3373 | 1113 "-*- texinfo -*-\n\ |
5781 | 1114 @deftypefn {Built-in Function} {} warning (@var{template}, @dots{})\n\ |
7252 | 1115 @deftypefnx {Built-in Function} {} warning (@var{id}, @var{template}, @dots{})\n\ |
5781 | 1116 Format the optional arguments under the control of the template string\n\ |
1117 @var{template} using the same rules as the @code{printf} family of\n\ | |
1118 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
1119 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
1120 string @samp{warning: }.\n\ | |
1121 You should use this function when you want to notify the user\n\ | |
3600 | 1122 of an unusual condition, but only when it makes sense for your program\n\ |
1123 to go on.\n\ | |
5781 | 1124 \n\ |
1125 The optional message identifier allows users to enable or disable\n\ | |
1126 warnings tagged by @var{id}. The special identifier @samp{\"all\"} may\n\ | |
1127 be used to set the state of all warnings.\n\ | |
1128 \n\ | |
1129 @deftypefnx {Built-in Function} {} warning (\"on\", @var{id})\n\ | |
1130 @deftypefnx {Built-in Function} {} warning (\"off\", @var{id})\n\ | |
1131 @deftypefnx {Built-in Function} {} warning (\"error\", @var{id})\n\ | |
1132 @deftypefnx {Built-in Function} {} warning (\"query\", @var{id})\n\ | |
6653 | 1133 Set or query the state of a particular warning using the identifier\n\ |
5781 | 1134 @var{id}. If the identifier is omitted, a value of @samp{\"all\"} is\n\ |
1135 assumed. If you set the state of a warning to @samp{\"error\"}, the\n\ | |
1136 warning named by @var{id} is handled as if it were an error instead.\n\ | |
5783 | 1137 @seealso{warning_ids}\n\ |
3373 | 1138 @end deftypefn") |
1489 | 1139 { |
5567 | 1140 octave_value retval; |
3934 | 1141 |
5567 | 1142 int nargin = args.length (); |
1143 int argc = nargin + 1; | |
3934 | 1144 |
3935 | 1145 bool done = false; |
3934 | 1146 |
5567 | 1147 if (argc > 1 && args.all_strings_p ()) |
3935 | 1148 { |
1149 string_vector argv = args.make_argv ("warning"); | |
1150 | |
1151 if (! error_state) | |
3934 | 1152 { |
5567 | 1153 std::string arg1 = argv(1); |
1154 std::string arg2 = "all"; | |
1155 | |
1156 if (argc == 3) | |
1157 arg2 = argv(2); | |
1158 | |
1159 if (arg1 == "on" || arg1 == "off" || arg1 == "error") | |
3934 | 1160 { |
5567 | 1161 Octave_map old_warning_options = warning_options; |
1162 | |
1163 if (arg2 == "all") | |
1164 { | |
1165 Octave_map tmp; | |
3934 | 1166 |
7202 | 1167 Cell id (1, 1); |
1168 Cell st (1, 1); | |
1169 | |
1170 id(0) = arg2; | |
1171 st(0) = arg1; | |
1172 | |
1173 // Since internal Octave functions are not | |
1174 // compatible, turning all warnings into errors | |
1175 // should leave the state of | |
1176 // Octave:matlab-incompatible alone. | |
1177 | |
1178 if (arg1 == "error" | |
1179 && warning_options.contains ("identifier")) | |
1180 { | |
7206 | 1181 octave_idx_type n = 1; |
1182 | |
7202 | 1183 Cell tid = warning_options.contents ("identifier"); |
1184 Cell tst = warning_options.contents ("state"); | |
1185 | |
1186 for (octave_idx_type i = 0; i < tid.numel (); i++) | |
1187 { | |
1188 octave_value vid = tid(i); | |
1189 | |
7206 | 1190 if (vid.is_string ()) |
7202 | 1191 { |
7206 | 1192 std::string key = vid.string_value (); |
7202 | 1193 |
7206 | 1194 if (key == "Octave:matlab-incompatible" |
1195 || key == "Octave:single-quote-string") | |
1196 { | |
1197 id.resize (dim_vector (1, n+1)); | |
1198 st.resize (dim_vector (1, n+1)); | |
7202 | 1199 |
7206 | 1200 id(n) = tid(i); |
1201 st(n) = tst(i); | |
1202 | |
1203 n++; | |
1204 } | |
7202 | 1205 } |
1206 } | |
1207 } | |
1208 | |
1209 tmp.assign ("identifier", id); | |
1210 tmp.assign ("state", st); | |
5567 | 1211 |
1212 warning_options = tmp; | |
1213 | |
3935 | 1214 done = true; |
1215 } | |
5567 | 1216 else if (arg2 == "backtrace") |
1217 { | |
1218 if (arg1 != "error") | |
1219 { | |
1220 Vbacktrace_on_warning = (arg1 == "on"); | |
1221 done = true; | |
1222 } | |
1223 } | |
1224 else if (arg2 == "debug") | |
1225 { | |
1226 if (arg1 != "error") | |
1227 { | |
5794 | 1228 Vdebug_on_warning = (arg1 == "on"); |
5567 | 1229 done = true; |
1230 } | |
1231 } | |
1232 else if (arg2 == "verbose") | |
1233 { | |
1234 if (arg1 != "error") | |
1235 { | |
1236 Vverbose_warning = (arg1 == "on"); | |
1237 done = true; | |
1238 } | |
1239 } | |
5582 | 1240 else if (arg2 == "quiet") |
1241 { | |
1242 if (arg1 != "error") | |
1243 { | |
1244 Vquiet_warning = (arg1 == "on"); | |
1245 done = true; | |
1246 } | |
1247 } | |
5567 | 1248 else |
3935 | 1249 { |
5567 | 1250 if (arg2 == "last") |
1251 arg2 = Vlast_warning_id; | |
1252 | |
1253 if (arg2 == "all") | |
5794 | 1254 initialize_warning_options (arg1); |
5567 | 1255 else |
1256 { | |
1257 Cell ident = warning_options.contents ("identifier"); | |
1258 Cell state = warning_options.contents ("state"); | |
1259 | |
1260 octave_idx_type nel = ident.numel (); | |
1261 | |
1262 bool found = false; | |
1263 | |
1264 for (octave_idx_type i = 0; i < nel; i++) | |
1265 { | |
1266 if (ident(i).string_value () == arg2) | |
1267 { | |
5775 | 1268 // FIXME -- if state for "all" is |
5567 | 1269 // same as arg1, we can simply remove the |
1270 // item from the list. | |
1271 | |
1272 state(i) = arg1; | |
1273 warning_options.assign ("state", state); | |
1274 found = true; | |
1275 break; | |
1276 } | |
1277 } | |
1278 | |
1279 if (! found) | |
1280 { | |
5775 | 1281 // FIXME -- if state for "all" is |
5567 | 1282 // same as arg1, we don't need to do anything. |
1283 | |
1284 ident.resize (dim_vector (1, nel+1)); | |
1285 state.resize (dim_vector (1, nel+1)); | |
1286 | |
1287 ident(nel) = arg2; | |
1288 state(nel) = arg1; | |
1289 | |
1290 warning_options.clear (); | |
1291 | |
1292 warning_options.assign ("identifier", ident); | |
1293 warning_options.assign ("state", state); | |
1294 } | |
1295 } | |
1296 | |
3935 | 1297 done = true; |
1298 } | |
5567 | 1299 |
1300 if (done && nargout > 0) | |
6427 | 1301 retval = old_warning_options; |
5567 | 1302 } |
1303 else if (arg1 == "query") | |
1304 { | |
1305 if (arg2 == "all") | |
1306 retval = warning_options; | |
1307 else if (arg2 == "backtrace" || arg2 == "debug" | |
5582 | 1308 || arg2 == "verbose" || arg2 == "quiet") |
5567 | 1309 { |
1310 Octave_map tmp; | |
1311 tmp.assign ("identifier", arg2); | |
1312 if (arg2 == "backtrace") | |
1313 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); | |
1314 else if (arg2 == "debug") | |
1315 tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); | |
5582 | 1316 else if (arg2 == "verbose") |
1317 tmp.assign ("state", Vverbose_warning ? "on" : "off"); | |
5567 | 1318 else |
5582 | 1319 tmp.assign ("state", Vquiet_warning ? "on" : "off"); |
1320 | |
1321 retval = tmp; | |
5567 | 1322 } |
1323 else | |
3935 | 1324 { |
5567 | 1325 if (arg2 == "last") |
1326 arg2 = Vlast_warning_id; | |
1327 | |
1328 Cell ident = warning_options.contents ("identifier"); | |
1329 Cell state = warning_options.contents ("state"); | |
1330 | |
1331 octave_idx_type nel = ident.numel (); | |
1332 | |
1333 bool found = false; | |
1334 | |
1335 std::string val; | |
1336 | |
1337 for (octave_idx_type i = 0; i < nel; i++) | |
1338 { | |
1339 if (ident(i).string_value () == arg2) | |
1340 { | |
1341 val = state(i).string_value (); | |
1342 found = true; | |
1343 break; | |
1344 } | |
1345 } | |
1346 | |
5781 | 1347 if (! found) |
1348 { | |
1349 for (octave_idx_type i = 0; i < nel; i++) | |
1350 { | |
1351 if (ident(i).string_value () == "all") | |
1352 { | |
1353 val = state(i).string_value (); | |
1354 found = true; | |
1355 break; | |
1356 } | |
1357 } | |
1358 } | |
1359 | |
5567 | 1360 if (found) |
1361 { | |
1362 Octave_map tmp; | |
1363 | |
1364 tmp.assign ("identifier", arg2); | |
1365 tmp.assign ("state", val); | |
1366 | |
1367 retval = tmp; | |
1368 } | |
1369 else | |
5781 | 1370 error ("warning: unable to find default warning state!"); |
3935 | 1371 } |
5567 | 1372 |
1373 done = true; | |
3935 | 1374 } |
3934 | 1375 } |
1376 } | |
5567 | 1377 else if (argc == 1) |
1378 { | |
1379 retval = warning_options; | |
3934 | 1380 |
5567 | 1381 done = true; |
1382 } | |
1383 else if (argc == 2) | |
1384 { | |
1385 octave_value arg = args(0); | |
1386 | |
1387 Octave_map old_warning_options = warning_options; | |
1388 | |
1389 if (arg.is_map ()) | |
1390 { | |
1391 Octave_map m = arg.map_value (); | |
1392 | |
1393 if (m.contains ("identifier") && m.contains ("state")) | |
6427 | 1394 warning_options = m; |
5567 | 1395 else |
1396 error ("warning: expecting structure with fields `identifier' and `state'"); | |
1397 | |
1398 done = true; | |
1399 | |
1400 if (nargout > 0) | |
1401 retval = old_warning_options; | |
1402 } | |
1403 } | |
1404 | |
1405 if (! (error_state || done)) | |
3935 | 1406 { |
5567 | 1407 octave_value_list nargs = args; |
1408 | |
1409 std::string id; | |
1410 | |
1411 if (nargin > 1) | |
1412 { | |
1413 std::string arg1 = args(0).string_value (); | |
1414 | |
1415 if (! error_state) | |
1416 { | |
8021 | 1417 if (arg1.find ('%') == std::string::npos) |
5567 | 1418 { |
1419 id = arg1; | |
1420 | |
1421 nargs.resize (nargin-1); | |
1422 | |
1423 for (int i = 1; i < nargin; i++) | |
1424 nargs(i-1) = args(i); | |
1425 } | |
1426 } | |
1427 else | |
1428 return retval; | |
1429 } | |
1430 | |
3935 | 1431 std::string prev_msg = Vlast_warning_message; |
1432 | |
5567 | 1433 std::string curr_msg = handle_message (warning_with_id, id.c_str (), |
1434 "unspecified warning", nargs); | |
3935 | 1435 |
1436 if (nargout > 0) | |
5567 | 1437 retval = prev_msg; |
3935 | 1438 } |
1439 | |
3934 | 1440 return retval; |
1441 } | |
1442 | |
5904 | 1443 void |
5794 | 1444 disable_warning (const std::string& id) |
1445 { | |
1446 octave_value_list args; | |
1447 | |
1448 args(1) = id; | |
1449 args(0) = "off"; | |
1450 | |
1451 Fwarning (args, 0); | |
1452 } | |
1453 | |
1454 void | |
1455 initialize_default_warning_state (void) | |
1456 { | |
1457 initialize_warning_options ("on"); | |
1458 | |
1459 // Most people will want to have the following disabled. | |
1460 | |
1461 disable_warning ("Octave:array-to-scalar"); | |
1462 disable_warning ("Octave:array-to-vector"); | |
1463 disable_warning ("Octave:empty-list-elements"); | |
1464 disable_warning ("Octave:fortran-indexing"); | |
1465 disable_warning ("Octave:imag-to-real"); | |
1466 disable_warning ("Octave:matlab-incompatible"); | |
1467 disable_warning ("Octave:missing-semicolon"); | |
1468 disable_warning ("Octave:neg-dim-as-zero"); | |
1469 disable_warning ("Octave:resize-on-range-error"); | |
1470 disable_warning ("Octave:separator-insert"); | |
1471 disable_warning ("Octave:single-quote-string"); | |
1472 disable_warning ("Octave:str-to-num"); | |
1473 disable_warning ("Octave:string-concat"); | |
1474 disable_warning ("Octave:variable-switch-label"); | |
8039
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1475 disable_warning ("Octave:int-convert-nan"); |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1476 disable_warning ("Octave:int-convert-non-int-val"); |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1477 disable_warning ("Octave:int-convert-overflow"); |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1478 disable_warning ("Octave:int-math-overflow"); |
9588
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
1479 disable_warning ("Octave:complex-cmp-ops"); |
5794 | 1480 } |
1481 | |
6361 | 1482 DEFUN (lasterror, args, , |
1483 "-*- texinfo -*-\n\ | |
1484 @deftypefn {Built-in Function} {@var{err} =} lasterror (@var{err})\n\ | |
1485 @deftypefnx {Built-in Function} {} lasterror ('reset')\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1486 Returns or sets the last error message. Called without any arguments\n\ |
6361 | 1487 returns a structure containing the last error message, as well as other\n\ |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1488 information related to this error. The elements of this structure are:\n\ |
6361 | 1489 \n\ |
1490 @table @asis\n\ | |
1491 @item 'message'\n\ | |
1492 The text of the last error message\n\ | |
1493 @item 'identifier'\n\ | |
1494 The message identifier of this error message\n\ | |
1495 @item 'stack'\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1496 A structure containing information on where the message occurred. This might\n\ |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8333
diff
changeset
|
1497 be an empty structure if this in the case where this information cannot\n\ |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1498 be obtained. The fields of this structure are:\n\ |
6361 | 1499 \n\ |
1500 @table @asis\n\ | |
1501 @item 'file'\n\ | |
1502 The name of the file where the error occurred\n\ | |
1503 @item 'name'\n\ | |
7001 | 1504 The name of function in which the error occurred\n\ |
6361 | 1505 @item 'line'\n\ |
7001 | 1506 The line number at which the error occurred\n\ |
6361 | 1507 @item 'column'\n\ |
1508 An optional field with the column number at which the error occurred\n\ | |
1509 @end table\n\ | |
1510 @end table\n\ | |
1511 \n\ | |
1512 The @var{err} structure may also be passed to @code{lasterror} to set the\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1513 information about the last error. The only constraint on @var{err} in that\n\ |
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1514 case is that it is a scalar structure. Any fields of @var{err} that match\n\ |
6361 | 1515 the above are set to the value passed in @var{err}, while other fields are\n\ |
1516 set to their default values.\n\ | |
1517 \n\ | |
1518 If @code{lasterror} is called with the argument 'reset', all values take\n\ | |
1519 their default values.\n\ | |
1520 @end deftypefn") | |
1521 { | |
1522 octave_value retval; | |
1523 int nargin = args.length(); | |
1524 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1525 unwind_protect frame; |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1526 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1527 frame.protect_var (error_state); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1528 error_state = 0; |
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1529 |
6361 | 1530 if (nargin < 2) |
1531 { | |
1532 Octave_map err; | |
1533 | |
1534 err.assign ("message", Vlast_error_message); | |
1535 err.assign ("identifier", Vlast_error_id); | |
1536 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1537 err.assign ("stack", octave_value (Vlast_error_stack)); |
6361 | 1538 |
1539 if (nargin == 1) | |
1540 { | |
1541 if (args(0).is_string()) | |
1542 { | |
6483 | 1543 if (args(0).string_value () == "reset") |
6361 | 1544 { |
1545 Vlast_error_message = std::string(); | |
1546 Vlast_error_id = std::string(); | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1547 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1548 Vlast_error_stack = initialize_last_error_stack (); |
6361 | 1549 } |
1550 else | |
1551 error("lasterror: unrecognized string argument"); | |
1552 } | |
1553 else if (args(0).is_map ()) | |
1554 { | |
6483 | 1555 Octave_map new_err = args(0).map_value (); |
6361 | 1556 std::string new_error_message; |
1557 std::string new_error_id; | |
1558 std::string new_error_file; | |
1559 std::string new_error_name; | |
1560 int new_error_line = -1; | |
1561 int new_error_column = -1; | |
1562 | |
6483 | 1563 if (! error_state && new_err.contains ("message")) |
6361 | 1564 { |
1565 const std::string tmp = | |
6483 | 1566 new_err.contents("message")(0).string_value (); |
6361 | 1567 new_error_message = tmp; |
1568 } | |
1569 | |
6483 | 1570 if (! error_state && new_err.contains ("identifier")) |
6361 | 1571 { |
1572 const std::string tmp = | |
6483 | 1573 new_err.contents("identifier")(0).string_value (); |
6361 | 1574 new_error_id = tmp; |
1575 } | |
1576 | |
6483 | 1577 if (! error_state && new_err.contains ("stack")) |
6361 | 1578 { |
1579 Octave_map new_err_stack = | |
6483 | 1580 new_err.contents("identifier")(0).map_value (); |
6361 | 1581 |
6483 | 1582 if (! error_state && new_err_stack.contains ("file")) |
6361 | 1583 { |
1584 const std::string tmp = | |
6483 | 1585 new_err_stack.contents("file")(0).string_value (); |
6361 | 1586 new_error_file = tmp; |
1587 } | |
1588 | |
6483 | 1589 if (! error_state && new_err_stack.contains ("name")) |
6361 | 1590 { |
1591 const std::string tmp = | |
6483 | 1592 new_err_stack.contents("name")(0).string_value (); |
6361 | 1593 new_error_name = tmp; |
1594 } | |
1595 | |
6483 | 1596 if (! error_state && new_err_stack.contains ("line")) |
6361 | 1597 { |
1598 const int tmp = | |
6483 | 1599 new_err_stack.contents("line")(0).nint_value (); |
6361 | 1600 new_error_line = tmp; |
1601 } | |
1602 | |
6483 | 1603 if (! error_state && new_err_stack.contains ("column")) |
6361 | 1604 { |
1605 const int tmp = | |
6483 | 1606 new_err_stack.contents("column")(0).nint_value (); |
6361 | 1607 new_error_column = tmp; |
1608 } | |
1609 } | |
1610 | |
1611 if (! error_state) | |
1612 { | |
1613 Vlast_error_message = new_error_message; | |
1614 Vlast_error_id = new_error_id; | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1615 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1616 octave_idx_type curr_frame = -1; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1617 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1618 Vlast_error_stack |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1619 = octave_call_stack::backtrace (0, curr_frame); |
6361 | 1620 } |
1621 } | |
1622 else | |
1623 error ("lasterror: argument must be a structure or a string"); | |
1624 } | |
1625 | |
6483 | 1626 if (! error_state) |
6361 | 1627 retval = err; |
1628 } | |
1629 else | |
1630 print_usage (); | |
1631 | |
1632 return retval; | |
1633 } | |
1634 | |
5567 | 1635 DEFUN (lasterr, args, nargout, |
3935 | 1636 "-*- texinfo -*-\n\ |
5567 | 1637 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lasterr (@var{msg}, @var{msgid})\n\ |
3935 | 1638 Without any arguments, return the last error message. With one\n\ |
5567 | 1639 argument, set the last error message to @var{msg}. With two arguments,\n\ |
1640 also set the last message identifier.\n\ | |
3935 | 1641 @end deftypefn") |
1642 { | |
1643 octave_value_list retval; | |
1644 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1645 unwind_protect frame; |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1646 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1647 frame.protect_var (error_state); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1648 error_state = 0; |
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1649 |
3935 | 1650 int argc = args.length () + 1; |
1651 | |
5567 | 1652 if (argc < 4) |
5335 | 1653 { |
1654 string_vector argv = args.make_argv ("lasterr"); | |
3935 | 1655 |
5335 | 1656 if (! error_state) |
1657 { | |
5567 | 1658 std::string prev_error_id = Vlast_error_id; |
1659 std::string prev_error_message = Vlast_error_message; | |
1660 | |
1661 if (argc > 2) | |
1662 Vlast_error_id = argv(2); | |
1663 | |
1664 if (argc > 1) | |
5335 | 1665 Vlast_error_message = argv(1); |
5567 | 1666 |
1667 if (argc == 1 || nargout > 0) | |
1668 { | |
1669 retval(1) = prev_error_id; | |
1670 retval(0) = prev_error_message; | |
1671 } | |
5335 | 1672 } |
5567 | 1673 else |
5582 | 1674 error ("lasterr: expecting arguments to be character strings"); |
5335 | 1675 } |
3935 | 1676 else |
5823 | 1677 print_usage (); |
3935 | 1678 |
1679 return retval; | |
1680 } | |
1681 | |
4699 | 1682 // For backward compatibility. |
1683 DEFALIAS (error_text, lasterr); | |
1684 DEFALIAS (__error_text__, lasterr); | |
1685 | |
5567 | 1686 DEFUN (lastwarn, args, nargout, |
3934 | 1687 "-*- texinfo -*-\n\ |
5567 | 1688 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lastwarn (@var{msg}, @var{msgid})\n\ |
3935 | 1689 Without any arguments, return the last warning message. With one\n\ |
5567 | 1690 argument, set the last warning message to @var{msg}. With two arguments,\n\ |
1691 also set the last message identifier.\n\ | |
3934 | 1692 @end deftypefn") |
1693 { | |
1694 octave_value_list retval; | |
1695 | |
1696 int argc = args.length () + 1; | |
1697 | |
5567 | 1698 if (argc < 4) |
1699 { | |
1700 string_vector argv = args.make_argv ("lastwarn"); | |
1701 | |
1702 if (! error_state) | |
1703 { | |
1704 std::string prev_warning_id = Vlast_warning_id; | |
1705 std::string prev_warning_message = Vlast_warning_message; | |
1706 | |
1707 if (argc > 2) | |
1708 Vlast_warning_id = argv(2); | |
3934 | 1709 |
5567 | 1710 if (argc > 1) |
1711 Vlast_warning_message = argv(1); | |
1712 | |
1713 if (argc == 1 || nargout > 0) | |
1714 { | |
5582 | 1715 warning_state = 0; |
5567 | 1716 retval(1) = prev_warning_id; |
1717 retval(0) = prev_warning_message; | |
1718 } | |
1719 } | |
1720 else | |
1721 error ("lastwarn: expecting arguments to be character strings"); | |
1722 } | |
3934 | 1723 else |
5823 | 1724 print_usage (); |
3934 | 1725 |
1726 return retval; | |
897 | 1727 } |
1728 | |
1957 | 1729 DEFUN (usage, args, , |
3373 | 1730 "-*- texinfo -*-\n\ |
1731 @deftypefn {Built-in Function} {} usage (@var{msg})\n\ | |
1732 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\ | |
1733 set Octave's internal error state such that control will return to the\n\ | |
1734 top level without evaluating any more commands. This is useful for\n\ | |
1735 aborting from functions.\n\ | |
1736 \n\ | |
1737 After @code{usage} is evaluated, Octave will print a traceback of all\n\ | |
1738 the function calls leading to the usage message.\n\ | |
899 | 1739 \n\ |
3373 | 1740 You should use this function for reporting problems errors that result\n\ |
1741 from an improper call to a function, such as calling a function with an\n\ | |
1742 incorrect number of arguments, or with arguments of the wrong type. For\n\ | |
1743 example, most functions distributed with Octave begin with code like\n\ | |
1744 this\n\ | |
1745 \n\ | |
1746 @example\n\ | |
1747 @group\n\ | |
1748 if (nargin != 2)\n\ | |
1749 usage (\"foo (a, b)\");\n\ | |
1750 endif\n\ | |
1751 @end group\n\ | |
1752 @end example\n\ | |
1753 \n\ | |
1754 @noindent\n\ | |
1755 to check for the proper number of arguments.\n\ | |
1756 @end deftypefn") | |
899 | 1757 { |
3934 | 1758 octave_value_list retval; |
5567 | 1759 handle_message (usage_with_id, "", "unknown", args); |
3934 | 1760 return retval; |
899 | 1761 } |
1762 | |
5794 | 1763 DEFUN (beep_on_error, args, nargout, |
1764 "-*- texinfo -*-\n\ | |
1765 @deftypefn {Built-in Function} {@var{val} =} beep_on_error ()\n\ | |
1766 @deftypefnx {Built-in Function} {@var{old_val} =} beep_on_error (@var{new_val})\n\ | |
1767 Query or set the internal variable that controls whether Octave will try\n\ | |
1768 to ring the terminal bell before printing an error message.\n\ | |
1769 @end deftypefn") | |
3707 | 1770 { |
5794 | 1771 return SET_INTERNAL_VARIABLE (beep_on_error); |
3707 | 1772 } |
1773 | |
5794 | 1774 DEFUN (debug_on_error, args, nargout, |
3373 | 1775 "-*- texinfo -*-\n\ |
5794 | 1776 @deftypefn {Built-in Function} {@var{val} =} debug_on_error ()\n\ |
1777 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_error (@var{new_val})\n\ | |
1778 Query or set the internal variable that controls whether Octave will try\n\ | |
3707 | 1779 to enter the debugger when an error is encountered. This will also\n\ |
1780 inhibit printing of the normal traceback message (you will only see\n\ | |
5794 | 1781 the top-level error message).\n\ |
1782 @end deftypefn") | |
1783 { | |
1784 return SET_INTERNAL_VARIABLE (debug_on_error); | |
1785 } | |
3707 | 1786 |
5794 | 1787 DEFUN (debug_on_warning, args, nargout, |
3707 | 1788 "-*- texinfo -*-\n\ |
5794 | 1789 @deftypefn {Built-in Function} {@var{val} =} debug_on_warning ()\n\ |
1790 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_warning (@var{new_val})\n\ | |
1791 Query or set the internal variable that controls whether Octave will try\n\ | |
1792 to enter the debugger when a warning is encountered.\n\ | |
1793 @end deftypefn") | |
1794 { | |
1795 return SET_INTERNAL_VARIABLE (debug_on_warning); | |
2174 | 1796 } |
1797 | |
7977
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1798 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1799 last_error_message (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1800 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1801 return Vlast_error_message; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1802 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1803 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1804 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1805 last_error_id (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1806 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1807 return Vlast_error_id; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1808 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1809 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1810 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1811 last_warning_message (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1812 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1813 return Vlast_warning_message; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1814 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1815 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1816 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1817 last_warning_id (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1818 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1819 return Vlast_warning_id; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
1820 } |