1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1343
|
27 #include <cstdarg> |
1633
|
28 #include <cstring> |
1343
|
29 |
1728
|
30 #include <string> |
|
31 |
4051
|
32 #include "lo-sstream.h" |
|
33 |
1352
|
34 #include "defun.h" |
1
|
35 #include "error.h" |
3707
|
36 #include "input.h" |
1742
|
37 #include "pager.h" |
1352
|
38 #include "oct-obj.h" |
|
39 #include "utils.h" |
2370
|
40 #include "ov.h" |
3707
|
41 #include "ov-usr-fcn.h" |
|
42 #include "pt-pr-code.h" |
|
43 #include "pt-stmt.h" |
|
44 #include "toplev.h" |
|
45 #include "unwind-prot.h" |
2370
|
46 #include "variables.h" |
1
|
47 |
2174
|
48 // TRUE means that Octave will try to beep obnoxiously before printing |
|
49 // error messages. |
|
50 static bool Vbeep_on_error; |
|
51 |
3707
|
52 // TRUE means that Octave will try to enter the debugger when an error |
|
53 // is encountered. This will also inhibit printing of the normal |
|
54 // traceback message (you will only see the top-level error message). |
|
55 static bool Vdebug_on_error; |
|
56 |
|
57 // TRUE means that Octave will try to enter the debugger when a warning |
|
58 // is encountered. |
|
59 static bool Vdebug_on_warning; |
|
60 |
3935
|
61 // The text of the last error message. |
|
62 static std::string Vlast_error_message; |
|
63 |
3934
|
64 // The text of the last warning message. |
|
65 static std::string Vlast_warning_message; |
|
66 |
|
67 // The warning frequency for Matlab handle graphics backwards |
|
68 // compatibility warnings (currently not used). |
|
69 static std::string Vwarning_frequency = "once"; |
|
70 |
|
71 // The current warning state. Valid values are "on", "off", |
|
72 // "backtrace", or "debug". |
3935
|
73 std::string Vwarning_option = "backtrace"; |
3934
|
74 |
143
|
75 // Current error state. |
3935
|
76 // |
|
77 // Valid values: |
|
78 // |
|
79 // -2: an error has occurred, but don't print any messages. |
|
80 // -1: an error has occurred, we are printing a traceback |
|
81 // 0: no error |
|
82 // 1: an error has occurred |
|
83 // |
672
|
84 int error_state = 0; |
|
85 |
3489
|
86 // Current warning state. |
3935
|
87 // |
|
88 // Valid values: |
|
89 // |
|
90 // 0: no warning |
|
91 // 1: a warning has occurred |
|
92 // |
3489
|
93 int warning_state = 0; |
|
94 |
1489
|
95 // Tell the error handler whether to print messages, or just store |
|
96 // them for later. Used for handling errors in eval() and |
|
97 // the `unwind_protect' statement. |
4699
|
98 int buffer_error_messages = 0; |
1489
|
99 |
3815
|
100 // TRUE means error messages are turned off. |
|
101 bool discard_error_messages = false; |
|
102 |
4452
|
103 // TRUE means warning messages are turned off. |
|
104 bool discard_warning_messages = false; |
|
105 |
3811
|
106 // The message buffer. |
4051
|
107 static OSSTREAM *error_message_buffer = 0; |
143
|
108 |
4318
|
109 void |
|
110 reset_error_handler (void) |
|
111 { |
|
112 error_state = 0; |
|
113 warning_state = 0; |
4699
|
114 buffer_error_messages = 0; |
4318
|
115 discard_error_messages = false; |
|
116 } |
|
117 |
3491
|
118 // Warning messages are never buffered. |
|
119 |
|
120 static void |
|
121 vwarning (const char *name, const char *fmt, va_list args) |
|
122 { |
4452
|
123 if (discard_warning_messages) |
|
124 return; |
|
125 |
3491
|
126 flush_octave_stdout (); |
|
127 |
4051
|
128 OSSTREAM output_buf; |
3491
|
129 |
|
130 if (name) |
3761
|
131 output_buf << name << ": "; |
|
132 |
|
133 octave_vformat (output_buf, fmt, args); |
|
134 |
4051
|
135 output_buf << std::endl << OSSTREAM_ENDS; |
3491
|
136 |
3935
|
137 // XXX FIXME XXX -- we really want to capture the message before it |
|
138 // has all the formatting goop attached to it. We probably also |
|
139 // want just the message, not the traceback information. |
|
140 |
4051
|
141 std::string msg_string = OSSTREAM_STR (output_buf); |
3761
|
142 |
4051
|
143 OSSTREAM_FREEZE (output_buf); |
3934
|
144 |
3935
|
145 if (! warning_state) |
|
146 { |
|
147 // This is the first warning in a possible series. |
|
148 Vlast_warning_message = msg_string; |
|
149 } |
3934
|
150 |
3935
|
151 octave_diary << msg_string; |
|
152 |
|
153 std::cerr << msg_string; |
3491
|
154 } |
|
155 |
1
|
156 static void |
4732
|
157 verror (bool save_last_error, std::ostream& os, |
|
158 const char *name, const char *fmt, va_list args) |
1
|
159 { |
3815
|
160 if (discard_error_messages) |
|
161 return; |
|
162 |
3585
|
163 if (! buffer_error_messages) |
|
164 flush_octave_stdout (); |
914
|
165 |
2174
|
166 bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; |
1423
|
167 |
4051
|
168 OSSTREAM output_buf; |
1
|
169 |
2174
|
170 if (to_beep_or_not_to_beep_p) |
1423
|
171 output_buf << "\a"; |
3620
|
172 |
599
|
173 if (name) |
|
174 output_buf << name << ": "; |
3620
|
175 |
|
176 octave_vformat (output_buf, fmt, args); |
|
177 |
4051
|
178 output_buf << std::endl << OSSTREAM_ENDS; |
581
|
179 |
3935
|
180 // XXX FIXME XXX -- we really want to capture the message before it |
|
181 // has all the formatting goop attached to it. We probably also |
|
182 // want just the message, not the traceback information. |
|
183 |
4051
|
184 std::string msg_string = OSSTREAM_STR (output_buf); |
3935
|
185 |
4051
|
186 OSSTREAM_FREEZE (output_buf); |
3935
|
187 |
4731
|
188 if (! error_state && save_last_error) |
3935
|
189 { |
|
190 // This is the first error in a possible series. |
|
191 Vlast_error_message = msg_string; |
|
192 } |
|
193 |
1489
|
194 if (buffer_error_messages) |
|
195 { |
3941
|
196 std::string tmp = msg_string; |
1489
|
197 |
|
198 if (! error_message_buffer) |
|
199 { |
4051
|
200 error_message_buffer = new OSSTREAM; |
1489
|
201 |
|
202 // XXX FIXME XXX -- this is ugly, but it prevents |
|
203 // |
4699
|
204 // eval ("error (\"msg\")", "error (lasterr ())"); |
1489
|
205 // |
|
206 // from printing `error: ' twice. Assumes that the NAME we |
|
207 // have been given doesn't contain `:'. |
|
208 |
3935
|
209 size_t pos = msg_string.find (':'); |
3162
|
210 |
3935
|
211 if (pos != NPOS && pos < Vlast_error_message.length () - 2) |
|
212 tmp = msg_string.substr (pos+2); |
1489
|
213 } |
|
214 |
3935
|
215 *error_message_buffer << tmp; |
1489
|
216 } |
|
217 else |
|
218 { |
3935
|
219 octave_diary << msg_string; |
4732
|
220 os << msg_string; |
1489
|
221 } |
1
|
222 } |
|
223 |
1266
|
224 // Note that we don't actually print any message if the error string |
|
225 // is just "" or "\n". This allows error ("") and error ("\n") to |
|
226 // just set the error state. |
|
227 |
1005
|
228 static void |
4732
|
229 error_1 (std::ostream& os, const char *name, const char *fmt, va_list args) |
1005
|
230 { |
|
231 if (error_state != -2) |
|
232 { |
1489
|
233 if (fmt) |
1005
|
234 { |
1489
|
235 if (*fmt) |
1005
|
236 { |
1489
|
237 int len = strlen (fmt); |
|
238 if (fmt[len - 1] == '\n') |
1266
|
239 { |
1489
|
240 if (len > 1) |
1266
|
241 { |
1489
|
242 char *tmp_fmt = strsave (fmt); |
|
243 tmp_fmt[len - 1] = '\0'; |
4732
|
244 verror (true, os, name, tmp_fmt, args); |
1489
|
245 delete [] tmp_fmt; |
|
246 } |
1423
|
247 |
1489
|
248 error_state = -2; |
1266
|
249 } |
1489
|
250 else |
4732
|
251 verror (true, os, name, fmt, args); |
1005
|
252 } |
|
253 } |
1489
|
254 else |
|
255 panic ("error_1: invalid format"); |
1423
|
256 |
|
257 if (! error_state) |
|
258 error_state = 1; |
1005
|
259 } |
|
260 } |
|
261 |
1
|
262 void |
|
263 message (const char *name, const char *fmt, ...) |
|
264 { |
|
265 va_list args; |
|
266 va_start (args, fmt); |
4732
|
267 verror (false, std::cerr, name, fmt, args); |
1
|
268 va_end (args); |
|
269 } |
|
270 |
|
271 void |
|
272 usage (const char *fmt, ...) |
|
273 { |
|
274 va_list args; |
|
275 va_start (args, fmt); |
4732
|
276 verror (true, std::cerr, "usage", fmt, args); |
905
|
277 error_state = -1; |
1
|
278 va_end (args); |
|
279 } |
|
280 |
3707
|
281 static void |
3719
|
282 pr_where_2 (const char *fmt, va_list args) |
|
283 { |
|
284 if (fmt) |
|
285 { |
|
286 if (*fmt) |
|
287 { |
|
288 int len = strlen (fmt); |
|
289 if (fmt[len - 1] == '\n') |
|
290 { |
|
291 if (len > 1) |
|
292 { |
|
293 char *tmp_fmt = strsave (fmt); |
|
294 tmp_fmt[len - 1] = '\0'; |
4732
|
295 verror (false, std::cerr, 0, tmp_fmt, args); |
3719
|
296 delete [] tmp_fmt; |
|
297 } |
|
298 } |
|
299 else |
4732
|
300 verror (false, std::cerr, 0, fmt, args); |
3719
|
301 } |
|
302 } |
|
303 else |
|
304 panic ("pr_where_2: invalid format"); |
|
305 } |
|
306 |
|
307 static void |
3707
|
308 pr_where_1 (const char *fmt, ...) |
|
309 { |
|
310 va_list args; |
|
311 va_start (args, fmt); |
3719
|
312 pr_where_2 (fmt, args); |
3707
|
313 va_end (args); |
|
314 } |
|
315 |
|
316 static void |
4719
|
317 pr_where (const char *name, bool print_code = true) |
3707
|
318 { |
|
319 if (curr_statement) |
|
320 { |
4976
|
321 std::string nm; |
3707
|
322 |
4976
|
323 int l = -1; |
|
324 int c = -1; |
|
325 |
|
326 octave_function *fcn = curr_function; |
|
327 |
|
328 if (fcn) |
3708
|
329 { |
4976
|
330 nm = fcn->name (); |
|
331 |
|
332 if (nm == "error" || nm == "warning") |
|
333 fcn = curr_caller_function; |
|
334 |
|
335 if (fcn) |
|
336 { |
|
337 nm = fcn->fcn_file_name (); |
3708
|
338 |
4976
|
339 if (nm.empty ()) |
|
340 nm = fcn->name (); |
|
341 |
|
342 if (curr_statement) |
|
343 { |
|
344 l = curr_statement->line (); |
|
345 c = curr_statement->column (); |
|
346 } |
|
347 } |
3708
|
348 } |
3707
|
349 |
4976
|
350 if (nm.empty ()) |
|
351 { |
|
352 if (l > 0 && c > 0) |
|
353 pr_where_1 ("%s: near line %d, column %d:", name, l, c); |
|
354 } |
3708
|
355 else |
4976
|
356 { |
|
357 if (l > 0 && c > 0) |
|
358 pr_where_1 ("%s: in %s near line %d, column %d:", |
|
359 name, nm.c_str (), l, c); |
|
360 else |
|
361 pr_where_1 ("%s: in %s", name, nm.c_str ()); |
|
362 } |
3707
|
363 |
4719
|
364 if (print_code) |
|
365 { |
|
366 // XXX FIXME XXX -- Note that the column number is probably |
|
367 // not going to mean much here since the code is being |
|
368 // reproduced from the parse tree, and we are only showing |
|
369 // one statement even if there were multiple statements on |
|
370 // the original source line. |
3707
|
371 |
4719
|
372 OSSTREAM output_buf; |
3708
|
373 |
4719
|
374 output_buf << std::endl; |
3707
|
375 |
4719
|
376 tree_print_code tpc (output_buf, ">>> "); |
|
377 |
|
378 curr_statement->accept (tpc); |
3707
|
379 |
4719
|
380 output_buf << std::endl << OSSTREAM_ENDS; |
3707
|
381 |
4719
|
382 pr_where_1 ("%s", OSSTREAM_C_STR (output_buf)); |
3707
|
383 |
4719
|
384 OSSTREAM_FREEZE (output_buf); |
|
385 } |
3707
|
386 } |
|
387 } |
|
388 |
1
|
389 void |
|
390 warning (const char *fmt, ...) |
|
391 { |
3934
|
392 if (Vwarning_option != "off") |
|
393 { |
4014
|
394 if (curr_sym_tab != top_level_sym_tab |
|
395 && Vwarning_option == "backtrace" |
4452
|
396 && ! warning_state |
|
397 && ! discard_warning_messages) |
4719
|
398 pr_where ("warning", false); |
3986
|
399 |
3934
|
400 va_list args; |
|
401 va_start (args, fmt); |
|
402 vwarning ("warning", fmt, args); |
|
403 va_end (args); |
3707
|
404 |
3935
|
405 warning_state = 1; |
|
406 |
3934
|
407 if ((interactive || forced_interactive) |
|
408 && Vdebug_on_warning && curr_function) |
|
409 { |
|
410 unwind_protect_bool (Vdebug_on_warning); |
|
411 Vdebug_on_warning = false; |
3707
|
412 |
3934
|
413 do_keyboard (octave_value_list ()); |
3707
|
414 |
3934
|
415 unwind_protect::run (); |
|
416 } |
3707
|
417 } |
1
|
418 } |
|
419 |
|
420 void |
|
421 error (const char *fmt, ...) |
|
422 { |
3707
|
423 int init_state = error_state; |
|
424 |
1
|
425 va_list args; |
|
426 va_start (args, fmt); |
4732
|
427 error_1 (std::cerr, "error", fmt, args); |
1005
|
428 va_end (args); |
3707
|
429 |
|
430 if ((interactive || forced_interactive) |
|
431 && Vdebug_on_error && init_state == 0 && curr_function) |
|
432 { |
|
433 unwind_protect_bool (Vdebug_on_error); |
|
434 Vdebug_on_error = false; |
|
435 |
3708
|
436 pr_where ("error"); |
3707
|
437 |
|
438 error_state = 0; |
|
439 |
|
440 do_keyboard (octave_value_list ()); |
|
441 |
|
442 unwind_protect::run (); |
|
443 } |
1005
|
444 } |
436
|
445 |
1005
|
446 void |
|
447 parse_error (const char *fmt, ...) |
|
448 { |
|
449 va_list args; |
|
450 va_start (args, fmt); |
4732
|
451 error_1 (std::cerr, 0, fmt, args); |
1
|
452 va_end (args); |
|
453 } |
|
454 |
189
|
455 void |
1
|
456 panic (const char *fmt, ...) |
|
457 { |
|
458 va_list args; |
|
459 va_start (args, fmt); |
4699
|
460 buffer_error_messages = 0; |
3815
|
461 discard_error_messages = false; |
4732
|
462 verror (false, std::cerr, "panic", fmt, args); |
1
|
463 va_end (args); |
|
464 abort (); |
|
465 } |
|
466 |
4732
|
467 static void |
|
468 defun_usage_message_1 (const char *fmt, ...) |
|
469 { |
|
470 va_list args; |
|
471 va_start (args, fmt); |
|
472 error_1 (octave_stdout, 0, fmt, args); |
|
473 va_end (args); |
|
474 } |
|
475 |
|
476 void |
|
477 defun_usage_message (const std::string& msg) |
|
478 { |
|
479 defun_usage_message_1 ("%s", msg.c_str ()); |
|
480 } |
|
481 |
1489
|
482 typedef void (*error_fun)(const char *, ...); |
|
483 |
2086
|
484 extern octave_value_list Fsprintf (const octave_value_list&, int); |
1489
|
485 |
3934
|
486 static std::string |
2086
|
487 handle_message (error_fun f, const char *msg, const octave_value_list& args) |
528
|
488 { |
3934
|
489 std::string retval; |
528
|
490 |
3523
|
491 std::string tstr; |
1728
|
492 |
528
|
493 int nargin = args.length (); |
|
494 |
2745
|
495 if (nargin > 0) |
528
|
496 { |
3066
|
497 octave_value arg; |
|
498 |
|
499 if (nargin > 1) |
|
500 { |
|
501 octave_value_list tmp = Fsprintf (args, 1); |
|
502 arg = tmp(0); |
|
503 } |
|
504 else |
|
505 arg = args(0); |
2745
|
506 |
|
507 if (arg.is_defined ()) |
528
|
508 { |
2745
|
509 if (arg.is_string ()) |
|
510 { |
|
511 tstr = arg.string_value (); |
|
512 msg = tstr.c_str (); |
|
513 |
|
514 if (! msg) |
|
515 return retval; |
|
516 } |
|
517 else if (arg.is_empty ()) |
528
|
518 return retval; |
|
519 } |
|
520 } |
|
521 |
1489
|
522 // Ugh. |
|
523 |
|
524 int len = strlen (msg); |
|
525 if (msg[len - 1] == '\n') |
|
526 { |
|
527 if (len > 1) |
|
528 { |
|
529 char *tmp_msg = strsave (msg); |
|
530 tmp_msg[len - 1] = '\0'; |
|
531 f ("%s\n", tmp_msg); |
3934
|
532 retval = tmp_msg; |
1489
|
533 delete [] tmp_msg; |
|
534 } |
|
535 } |
|
536 else |
3934
|
537 { |
|
538 f ("%s", msg); |
|
539 retval = msg; |
|
540 } |
528
|
541 |
|
542 return retval; |
|
543 } |
|
544 |
1957
|
545 DEFUN (error, args, , |
3373
|
546 "-*- texinfo -*-\n\ |
|
547 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\ |
|
548 The @code{error} function formats the optional arguments under the\n\ |
|
549 control of the template string @var{template} using the same rules as\n\ |
|
550 the @code{printf} family of functions (@pxref{Formatted Output}).\n\ |
|
551 The resulting message is prefixed by the string @samp{error: } and\n\ |
|
552 printed on the @code{stderr} stream.\n\ |
|
553 \n\ |
|
554 Calling @code{error} also sets Octave's internal error state such that\n\ |
|
555 control will return to the top level without evaluating any more\n\ |
|
556 commands. This is useful for aborting from functions or scripts.\n\ |
897
|
557 \n\ |
3373
|
558 If the error message does not end with a new line character, Octave will\n\ |
|
559 print a traceback of all the function calls leading to the error. For\n\ |
|
560 example, given the following function definitions:\n\ |
|
561 \n\ |
|
562 @example\n\ |
|
563 @group\n\ |
|
564 function f () g () end\n\ |
|
565 function g () h () end\n\ |
|
566 function h () nargin == 1 || error (\"nargin != 1\"); end\n\ |
|
567 @end group\n\ |
|
568 @end example\n\ |
1489
|
569 \n\ |
3373
|
570 @noindent\n\ |
|
571 calling the function @code{f} will result in a list of messages that\n\ |
|
572 can help you to quickly locate the exact location of the error:\n\ |
1489
|
573 \n\ |
3373
|
574 @example\n\ |
|
575 @group\n\ |
|
576 f ()\n\ |
|
577 error: nargin != 1\n\ |
|
578 error: evaluating index expression near line 1, column 30\n\ |
|
579 error: evaluating binary operator `||' near line 1, column 27\n\ |
|
580 error: called from `h'\n\ |
|
581 error: called from `g'\n\ |
|
582 error: called from `f'\n\ |
|
583 @end group\n\ |
|
584 @end example\n\ |
|
585 \n\ |
|
586 If the error message ends in a new line character, Octave will print the\n\ |
|
587 message but will not display any traceback messages as it returns\n\ |
|
588 control to the top level. For example, modifying the error message\n\ |
|
589 in the previous example to end in a new line causes Octave to only print\n\ |
|
590 a single message:\n\ |
|
591 \n\ |
|
592 @example\n\ |
|
593 @group\n\ |
|
594 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\ |
|
595 f ()\n\ |
|
596 error: nargin != 1\n\ |
|
597 @end group\n\ |
|
598 @end example\n\ |
|
599 @end deftypefn") |
897
|
600 { |
3934
|
601 octave_value_list retval; |
|
602 handle_message (error, "unspecified error", args); |
|
603 return retval; |
1489
|
604 } |
897
|
605 |
3934
|
606 static inline octave_value_list |
|
607 set_warning_option (const std::string& state, |
3935
|
608 const std::string& frequency, int nargout) |
3934
|
609 { |
|
610 octave_value_list retval; |
|
611 |
|
612 if (nargout > 1) |
|
613 retval(1) = Vwarning_frequency; |
|
614 |
3935
|
615 if (nargout >= 0) |
3934
|
616 retval(0) = Vwarning_option; |
|
617 |
|
618 if (! state.empty ()) |
|
619 Vwarning_option = state; |
|
620 |
|
621 if (! frequency.empty ()) |
|
622 Vwarning_frequency = frequency; |
|
623 |
|
624 return retval; |
|
625 } |
|
626 |
3935
|
627 DEFUN (warning, args, nargout, |
3373
|
628 "-*- texinfo -*-\n\ |
|
629 @deftypefn {Built-in Function} {} warning (@var{msg})\n\ |
|
630 Print a warning message @var{msg} prefixed by the string @samp{warning: }. \n\ |
|
631 After printing the warning message, Octave will continue to execute\n\ |
3600
|
632 commands. You should use this function when you want to notify the user\n\ |
|
633 of an unusual condition, but only when it makes sense for your program\n\ |
|
634 to go on.\n\ |
3373
|
635 @end deftypefn") |
1489
|
636 { |
3934
|
637 octave_value_list retval; |
|
638 |
|
639 int argc = args.length () + 1; |
|
640 |
3935
|
641 bool done = false; |
3934
|
642 |
3935
|
643 if (args.all_strings_p ()) |
|
644 { |
|
645 string_vector argv = args.make_argv ("warning"); |
|
646 |
|
647 if (! error_state) |
3934
|
648 { |
3935
|
649 if (argc == 1) |
3934
|
650 { |
|
651 retval = set_warning_option ("", "", nargout); |
|
652 done = true; |
|
653 } |
3935
|
654 else if (argc == 2) |
|
655 { |
|
656 std::string arg = argv(1); |
3934
|
657 |
3935
|
658 if (arg == "on" || arg == "off" || arg == "backtrace") |
|
659 { |
|
660 retval = set_warning_option (arg, "", nargout); |
|
661 done = true; |
|
662 } |
|
663 else if (arg == "once" || arg == "always") |
|
664 { |
|
665 retval = set_warning_option ("", arg, nargout); |
|
666 done = true; |
|
667 } |
|
668 else if (arg == "debug") |
|
669 { |
4324
|
670 bind_builtin_variable ("debug_on_warning", true); |
3935
|
671 retval = set_warning_option ("", "", nargout); |
|
672 done = true; |
|
673 } |
|
674 } |
3934
|
675 } |
|
676 } |
|
677 |
3935
|
678 if (! done) |
|
679 { |
|
680 std::string prev_msg = Vlast_warning_message; |
|
681 |
|
682 std::string curr_msg |
|
683 = handle_message (warning, "unspecified warning", args); |
|
684 |
|
685 if (nargout > 0) |
|
686 retval(0) = Vlast_warning_message; |
|
687 } |
|
688 |
3934
|
689 return retval; |
|
690 } |
|
691 |
3935
|
692 DEFUN (lasterr, args, , |
|
693 "-*- texinfo -*-\n\ |
|
694 @deftypefn {Built-in Function} {} lasterr ()\n\ |
|
695 @deftypefnx {Built-in Function} {} lasterr (@var{msg})\n\ |
|
696 Without any arguments, return the last error message. With one\n\ |
5016
|
697 argument, set the last error message to @var{msg}.\n\ |
3935
|
698 @end deftypefn") |
|
699 { |
|
700 octave_value_list retval; |
|
701 |
|
702 int argc = args.length () + 1; |
|
703 |
|
704 string_vector argv = args.make_argv ("lasterr"); |
|
705 |
|
706 if (argc == 1) |
|
707 retval(0) = Vlast_error_message; |
|
708 else if (argc == 2) |
|
709 Vlast_error_message = argv(1); |
|
710 else |
|
711 print_usage ("lasterr"); |
|
712 |
|
713 return retval; |
|
714 } |
|
715 |
4699
|
716 // For backward compatibility. |
|
717 DEFALIAS (error_text, lasterr); |
|
718 DEFALIAS (__error_text__, lasterr); |
|
719 |
3934
|
720 DEFUN (lastwarn, args, , |
|
721 "-*- texinfo -*-\n\ |
|
722 @deftypefn {Built-in Function} {} lastwarn ()\n\ |
|
723 @deftypefnx {Built-in Function} {} lastwarn (@var{msg})\n\ |
3935
|
724 Without any arguments, return the last warning message. With one\n\ |
5016
|
725 argument, set the last warning message to @var{msg}.\n\ |
3934
|
726 @end deftypefn") |
|
727 { |
|
728 octave_value_list retval; |
|
729 |
|
730 int argc = args.length () + 1; |
|
731 |
|
732 string_vector argv = args.make_argv ("lastwarn"); |
|
733 |
|
734 if (argc == 1) |
|
735 retval(0) = Vlast_warning_message; |
|
736 else if (argc == 2) |
|
737 Vlast_warning_message = argv(1); |
|
738 else |
|
739 print_usage ("lastwarn"); |
|
740 |
|
741 return retval; |
897
|
742 } |
|
743 |
1957
|
744 DEFUN (usage, args, , |
3373
|
745 "-*- texinfo -*-\n\ |
|
746 @deftypefn {Built-in Function} {} usage (@var{msg})\n\ |
|
747 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\ |
|
748 set Octave's internal error state such that control will return to the\n\ |
|
749 top level without evaluating any more commands. This is useful for\n\ |
|
750 aborting from functions.\n\ |
|
751 \n\ |
|
752 After @code{usage} is evaluated, Octave will print a traceback of all\n\ |
|
753 the function calls leading to the usage message.\n\ |
899
|
754 \n\ |
3373
|
755 You should use this function for reporting problems errors that result\n\ |
|
756 from an improper call to a function, such as calling a function with an\n\ |
|
757 incorrect number of arguments, or with arguments of the wrong type. For\n\ |
|
758 example, most functions distributed with Octave begin with code like\n\ |
|
759 this\n\ |
|
760 \n\ |
|
761 @example\n\ |
|
762 @group\n\ |
|
763 if (nargin != 2)\n\ |
|
764 usage (\"foo (a, b)\");\n\ |
|
765 endif\n\ |
|
766 @end group\n\ |
|
767 @end example\n\ |
|
768 \n\ |
|
769 @noindent\n\ |
|
770 to check for the proper number of arguments.\n\ |
|
771 @end deftypefn") |
899
|
772 { |
3934
|
773 octave_value_list retval; |
|
774 handle_message (usage, "unknown", args); |
|
775 return retval; |
899
|
776 } |
|
777 |
2174
|
778 static int |
|
779 beep_on_error (void) |
|
780 { |
|
781 Vbeep_on_error = check_preference ("beep_on_error"); |
|
782 |
|
783 return 0; |
|
784 } |
|
785 |
3707
|
786 static int |
|
787 debug_on_error (void) |
|
788 { |
|
789 Vdebug_on_error = check_preference ("debug_on_error"); |
|
790 |
|
791 return 0; |
|
792 } |
|
793 |
|
794 static int |
|
795 debug_on_warning (void) |
|
796 { |
|
797 Vdebug_on_warning = check_preference ("debug_on_warning"); |
|
798 |
|
799 return 0; |
|
800 } |
|
801 |
2174
|
802 void |
|
803 symbols_of_error (void) |
|
804 { |
4233
|
805 DEFVAR (beep_on_error, false, beep_on_error, |
3373
|
806 "-*- texinfo -*-\n\ |
|
807 @defvr {Built-in Variable} beep_on_error\n\ |
|
808 If the value of @code{beep_on_error} is nonzero, Octave will try\n\ |
|
809 to ring your terminal's bell before printing an error message. The\n\ |
|
810 default value is 0.\n\ |
|
811 @end defvr"); |
3018
|
812 |
4233
|
813 DEFVAR (debug_on_error, false, debug_on_error, |
3707
|
814 "-*- texinfo -*-\n\ |
|
815 @defvr {Built-in Variable} debug_on_error\n\ |
|
816 If the value of @code{debug_on_error} is nonzero, Octave will try\n\ |
|
817 to enter the debugger when an error is encountered. This will also\n\ |
|
818 inhibit printing of the normal traceback message (you will only see\n\ |
|
819 the top-level error message). The default value is 0.\n\ |
|
820 @end defvr"); |
|
821 |
4233
|
822 DEFVAR (debug_on_warning, false, debug_on_warning, |
3707
|
823 "-*- texinfo -*-\n\ |
|
824 @defvr {Built-in Variable} debug_on_warning\n\ |
|
825 If the value of @code{debug_on_warning} is nonzero, Octave will try\n\ |
|
826 to enter the debugger when a warning is encountered. The default\n\ |
|
827 value is 0.\n\ |
|
828 @end defvr"); |
2174
|
829 } |
|
830 |
1
|
831 /* |
|
832 ;;; Local Variables: *** |
|
833 ;;; mode: C++ *** |
|
834 ;;; End: *** |
|
835 */ |