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 |
|
157 verror (const char *name, const char *fmt, va_list args) |
|
158 { |
3815
|
159 if (discard_error_messages) |
|
160 return; |
|
161 |
3585
|
162 if (! buffer_error_messages) |
|
163 flush_octave_stdout (); |
914
|
164 |
2174
|
165 bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; |
1423
|
166 |
4051
|
167 OSSTREAM output_buf; |
1
|
168 |
2174
|
169 if (to_beep_or_not_to_beep_p) |
1423
|
170 output_buf << "\a"; |
3620
|
171 |
599
|
172 if (name) |
|
173 output_buf << name << ": "; |
3620
|
174 |
|
175 octave_vformat (output_buf, fmt, args); |
|
176 |
4051
|
177 output_buf << std::endl << OSSTREAM_ENDS; |
581
|
178 |
3935
|
179 // XXX FIXME XXX -- we really want to capture the message before it |
|
180 // has all the formatting goop attached to it. We probably also |
|
181 // want just the message, not the traceback information. |
|
182 |
4051
|
183 std::string msg_string = OSSTREAM_STR (output_buf); |
3935
|
184 |
4051
|
185 OSSTREAM_FREEZE (output_buf); |
3935
|
186 |
|
187 if (! error_state && name && ! strcmp (name, "error")) |
|
188 { |
|
189 // This is the first error in a possible series. |
|
190 Vlast_error_message = msg_string; |
|
191 } |
|
192 |
1489
|
193 if (buffer_error_messages) |
|
194 { |
3941
|
195 std::string tmp = msg_string; |
1489
|
196 |
|
197 if (! error_message_buffer) |
|
198 { |
4051
|
199 error_message_buffer = new OSSTREAM; |
1489
|
200 |
|
201 // XXX FIXME XXX -- this is ugly, but it prevents |
|
202 // |
4699
|
203 // eval ("error (\"msg\")", "error (lasterr ())"); |
1489
|
204 // |
|
205 // from printing `error: ' twice. Assumes that the NAME we |
|
206 // have been given doesn't contain `:'. |
|
207 |
3935
|
208 size_t pos = msg_string.find (':'); |
3162
|
209 |
3935
|
210 if (pos != NPOS && pos < Vlast_error_message.length () - 2) |
|
211 tmp = msg_string.substr (pos+2); |
1489
|
212 } |
|
213 |
3935
|
214 *error_message_buffer << tmp; |
1489
|
215 } |
|
216 else |
|
217 { |
3935
|
218 octave_diary << msg_string; |
|
219 std::cerr << msg_string; |
1489
|
220 } |
1
|
221 } |
|
222 |
1266
|
223 // Note that we don't actually print any message if the error string |
|
224 // is just "" or "\n". This allows error ("") and error ("\n") to |
|
225 // just set the error state. |
|
226 |
1005
|
227 static void |
|
228 error_1 (const char *name, const char *fmt, va_list args) |
|
229 { |
|
230 if (error_state != -2) |
|
231 { |
1489
|
232 if (fmt) |
1005
|
233 { |
1489
|
234 if (*fmt) |
1005
|
235 { |
1489
|
236 int len = strlen (fmt); |
|
237 if (fmt[len - 1] == '\n') |
1266
|
238 { |
1489
|
239 if (len > 1) |
1266
|
240 { |
1489
|
241 char *tmp_fmt = strsave (fmt); |
|
242 tmp_fmt[len - 1] = '\0'; |
|
243 verror (name, tmp_fmt, args); |
|
244 delete [] tmp_fmt; |
|
245 } |
1423
|
246 |
1489
|
247 error_state = -2; |
1266
|
248 } |
1489
|
249 else |
|
250 verror (name, fmt, args); |
1005
|
251 } |
|
252 } |
1489
|
253 else |
|
254 panic ("error_1: invalid format"); |
1423
|
255 |
|
256 if (! error_state) |
|
257 error_state = 1; |
1005
|
258 } |
|
259 } |
|
260 |
1
|
261 void |
|
262 message (const char *name, const char *fmt, ...) |
|
263 { |
|
264 va_list args; |
|
265 va_start (args, fmt); |
|
266 verror (name, fmt, args); |
|
267 va_end (args); |
|
268 } |
|
269 |
|
270 void |
|
271 usage (const char *fmt, ...) |
|
272 { |
|
273 va_list args; |
|
274 va_start (args, fmt); |
905
|
275 error_state = -1; |
1
|
276 verror ("usage", fmt, args); |
|
277 va_end (args); |
|
278 } |
|
279 |
3707
|
280 static void |
3719
|
281 pr_where_2 (const char *fmt, va_list args) |
|
282 { |
|
283 if (fmt) |
|
284 { |
|
285 if (*fmt) |
|
286 { |
|
287 int len = strlen (fmt); |
|
288 if (fmt[len - 1] == '\n') |
|
289 { |
|
290 if (len > 1) |
|
291 { |
|
292 char *tmp_fmt = strsave (fmt); |
|
293 tmp_fmt[len - 1] = '\0'; |
|
294 verror (0, tmp_fmt, args); |
|
295 delete [] tmp_fmt; |
|
296 } |
|
297 } |
|
298 else |
|
299 verror (0, fmt, args); |
|
300 } |
|
301 } |
|
302 else |
|
303 panic ("pr_where_2: invalid format"); |
|
304 } |
|
305 |
|
306 static void |
3707
|
307 pr_where_1 (const char *fmt, ...) |
|
308 { |
|
309 va_list args; |
|
310 va_start (args, fmt); |
3719
|
311 pr_where_2 (fmt, args); |
3707
|
312 va_end (args); |
|
313 } |
|
314 |
|
315 static void |
3708
|
316 pr_where (const char *name) |
3707
|
317 { |
|
318 if (curr_statement) |
|
319 { |
3708
|
320 const char *f_nm = 0; |
3707
|
321 |
3708
|
322 if (curr_function) |
|
323 { |
|
324 std::string fcn_name = curr_function->function_name (); |
|
325 std::string file_name = curr_function->fcn_file_name (); |
|
326 |
|
327 f_nm = file_name.empty () ? fcn_name.c_str () : file_name.c_str (); |
|
328 } |
3707
|
329 |
|
330 int l = curr_statement->line (); |
|
331 int c = curr_statement->column (); |
|
332 |
3708
|
333 if (f_nm) |
|
334 pr_where_1 ("%s: in %s near line %d, column %d:", name, f_nm, l, c); |
|
335 else |
|
336 pr_where_1 ("%s: near line %d, column %d:", name, l, c); |
3707
|
337 |
3708
|
338 // XXX FIXME XXX -- Note that the column number is probably not |
|
339 // going to mean much here since the code is being reproduced |
|
340 // from the parse tree, and we are only showing one statement |
|
341 // even if there were multiple statements on the original source |
|
342 // line. |
3707
|
343 |
4051
|
344 OSSTREAM output_buf; |
3707
|
345 |
3764
|
346 output_buf << std::endl; |
3708
|
347 |
|
348 tree_print_code tpc (output_buf, ">>> "); |
3707
|
349 |
|
350 curr_statement->accept (tpc); |
|
351 |
4051
|
352 output_buf << std::endl << OSSTREAM_ENDS; |
3707
|
353 |
4051
|
354 pr_where_1 ("%s", OSSTREAM_C_STR (output_buf)); |
3707
|
355 |
4051
|
356 OSSTREAM_FREEZE (output_buf); |
3707
|
357 } |
|
358 } |
|
359 |
1
|
360 void |
|
361 warning (const char *fmt, ...) |
|
362 { |
3934
|
363 if (Vwarning_option != "off") |
|
364 { |
4014
|
365 if (curr_sym_tab != top_level_sym_tab |
|
366 && Vwarning_option == "backtrace" |
4452
|
367 && ! warning_state |
|
368 && ! discard_warning_messages) |
3986
|
369 pr_where ("warning"); |
|
370 |
3934
|
371 va_list args; |
|
372 va_start (args, fmt); |
|
373 vwarning ("warning", fmt, args); |
|
374 va_end (args); |
3707
|
375 |
3935
|
376 warning_state = 1; |
|
377 |
3934
|
378 if ((interactive || forced_interactive) |
|
379 && Vdebug_on_warning && curr_function) |
|
380 { |
|
381 unwind_protect_bool (Vdebug_on_warning); |
|
382 Vdebug_on_warning = false; |
3707
|
383 |
3934
|
384 do_keyboard (octave_value_list ()); |
3707
|
385 |
3934
|
386 unwind_protect::run (); |
|
387 } |
3707
|
388 } |
1
|
389 } |
|
390 |
|
391 void |
|
392 error (const char *fmt, ...) |
|
393 { |
3707
|
394 int init_state = error_state; |
|
395 |
1
|
396 va_list args; |
|
397 va_start (args, fmt); |
1005
|
398 error_1 ("error", fmt, args); |
|
399 va_end (args); |
3707
|
400 |
|
401 if ((interactive || forced_interactive) |
|
402 && Vdebug_on_error && init_state == 0 && curr_function) |
|
403 { |
|
404 unwind_protect_bool (Vdebug_on_error); |
|
405 Vdebug_on_error = false; |
|
406 |
3708
|
407 pr_where ("error"); |
3707
|
408 |
|
409 error_state = 0; |
|
410 |
|
411 do_keyboard (octave_value_list ()); |
|
412 |
|
413 unwind_protect::run (); |
|
414 } |
1005
|
415 } |
436
|
416 |
1005
|
417 void |
|
418 parse_error (const char *fmt, ...) |
|
419 { |
|
420 va_list args; |
|
421 va_start (args, fmt); |
|
422 error_1 (0, fmt, args); |
1
|
423 va_end (args); |
|
424 } |
|
425 |
189
|
426 void |
1
|
427 panic (const char *fmt, ...) |
|
428 { |
|
429 va_list args; |
|
430 va_start (args, fmt); |
4699
|
431 buffer_error_messages = 0; |
3815
|
432 discard_error_messages = false; |
1
|
433 verror ("panic", fmt, args); |
|
434 va_end (args); |
|
435 abort (); |
|
436 } |
|
437 |
1489
|
438 typedef void (*error_fun)(const char *, ...); |
|
439 |
2086
|
440 extern octave_value_list Fsprintf (const octave_value_list&, int); |
1489
|
441 |
3934
|
442 static std::string |
2086
|
443 handle_message (error_fun f, const char *msg, const octave_value_list& args) |
528
|
444 { |
3934
|
445 std::string retval; |
528
|
446 |
3523
|
447 std::string tstr; |
1728
|
448 |
528
|
449 int nargin = args.length (); |
|
450 |
2745
|
451 if (nargin > 0) |
528
|
452 { |
3066
|
453 octave_value arg; |
|
454 |
|
455 if (nargin > 1) |
|
456 { |
|
457 octave_value_list tmp = Fsprintf (args, 1); |
|
458 arg = tmp(0); |
|
459 } |
|
460 else |
|
461 arg = args(0); |
2745
|
462 |
|
463 if (arg.is_defined ()) |
528
|
464 { |
2745
|
465 if (arg.is_string ()) |
|
466 { |
|
467 tstr = arg.string_value (); |
|
468 msg = tstr.c_str (); |
|
469 |
|
470 if (! msg) |
|
471 return retval; |
|
472 } |
|
473 else if (arg.is_empty ()) |
528
|
474 return retval; |
|
475 } |
|
476 } |
|
477 |
1489
|
478 // Ugh. |
|
479 |
|
480 int len = strlen (msg); |
|
481 if (msg[len - 1] == '\n') |
|
482 { |
|
483 if (len > 1) |
|
484 { |
|
485 char *tmp_msg = strsave (msg); |
|
486 tmp_msg[len - 1] = '\0'; |
|
487 f ("%s\n", tmp_msg); |
3934
|
488 retval = tmp_msg; |
1489
|
489 delete [] tmp_msg; |
|
490 } |
|
491 } |
|
492 else |
3934
|
493 { |
|
494 f ("%s", msg); |
|
495 retval = msg; |
|
496 } |
528
|
497 |
|
498 return retval; |
|
499 } |
|
500 |
1957
|
501 DEFUN (error, args, , |
3373
|
502 "-*- texinfo -*-\n\ |
|
503 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\ |
|
504 The @code{error} function formats the optional arguments under the\n\ |
|
505 control of the template string @var{template} using the same rules as\n\ |
|
506 the @code{printf} family of functions (@pxref{Formatted Output}).\n\ |
|
507 The resulting message is prefixed by the string @samp{error: } and\n\ |
|
508 printed on the @code{stderr} stream.\n\ |
|
509 \n\ |
|
510 Calling @code{error} also sets Octave's internal error state such that\n\ |
|
511 control will return to the top level without evaluating any more\n\ |
|
512 commands. This is useful for aborting from functions or scripts.\n\ |
897
|
513 \n\ |
3373
|
514 If the error message does not end with a new line character, Octave will\n\ |
|
515 print a traceback of all the function calls leading to the error. For\n\ |
|
516 example, given the following function definitions:\n\ |
|
517 \n\ |
|
518 @example\n\ |
|
519 @group\n\ |
|
520 function f () g () end\n\ |
|
521 function g () h () end\n\ |
|
522 function h () nargin == 1 || error (\"nargin != 1\"); end\n\ |
|
523 @end group\n\ |
|
524 @end example\n\ |
1489
|
525 \n\ |
3373
|
526 @noindent\n\ |
|
527 calling the function @code{f} will result in a list of messages that\n\ |
|
528 can help you to quickly locate the exact location of the error:\n\ |
1489
|
529 \n\ |
3373
|
530 @example\n\ |
|
531 @group\n\ |
|
532 f ()\n\ |
|
533 error: nargin != 1\n\ |
|
534 error: evaluating index expression near line 1, column 30\n\ |
|
535 error: evaluating binary operator `||' near line 1, column 27\n\ |
|
536 error: called from `h'\n\ |
|
537 error: called from `g'\n\ |
|
538 error: called from `f'\n\ |
|
539 @end group\n\ |
|
540 @end example\n\ |
|
541 \n\ |
|
542 If the error message ends in a new line character, Octave will print the\n\ |
|
543 message but will not display any traceback messages as it returns\n\ |
|
544 control to the top level. For example, modifying the error message\n\ |
|
545 in the previous example to end in a new line causes Octave to only print\n\ |
|
546 a single message:\n\ |
|
547 \n\ |
|
548 @example\n\ |
|
549 @group\n\ |
|
550 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\ |
|
551 f ()\n\ |
|
552 error: nargin != 1\n\ |
|
553 @end group\n\ |
|
554 @end example\n\ |
|
555 @end deftypefn") |
897
|
556 { |
3934
|
557 octave_value_list retval; |
|
558 handle_message (error, "unspecified error", args); |
|
559 return retval; |
1489
|
560 } |
897
|
561 |
3934
|
562 static inline octave_value_list |
|
563 set_warning_option (const std::string& state, |
3935
|
564 const std::string& frequency, int nargout) |
3934
|
565 { |
|
566 octave_value_list retval; |
|
567 |
|
568 if (nargout > 1) |
|
569 retval(1) = Vwarning_frequency; |
|
570 |
3935
|
571 if (nargout >= 0) |
3934
|
572 retval(0) = Vwarning_option; |
|
573 |
|
574 if (! state.empty ()) |
|
575 Vwarning_option = state; |
|
576 |
|
577 if (! frequency.empty ()) |
|
578 Vwarning_frequency = frequency; |
|
579 |
|
580 return retval; |
|
581 } |
|
582 |
3935
|
583 DEFUN (warning, args, nargout, |
3373
|
584 "-*- texinfo -*-\n\ |
|
585 @deftypefn {Built-in Function} {} warning (@var{msg})\n\ |
|
586 Print a warning message @var{msg} prefixed by the string @samp{warning: }. \n\ |
|
587 After printing the warning message, Octave will continue to execute\n\ |
3600
|
588 commands. You should use this function when you want to notify the user\n\ |
|
589 of an unusual condition, but only when it makes sense for your program\n\ |
|
590 to go on.\n\ |
3373
|
591 @end deftypefn") |
1489
|
592 { |
3934
|
593 octave_value_list retval; |
|
594 |
|
595 int argc = args.length () + 1; |
|
596 |
3935
|
597 bool done = false; |
3934
|
598 |
3935
|
599 if (args.all_strings_p ()) |
|
600 { |
|
601 string_vector argv = args.make_argv ("warning"); |
|
602 |
|
603 if (! error_state) |
3934
|
604 { |
3935
|
605 if (argc == 1) |
3934
|
606 { |
|
607 retval = set_warning_option ("", "", nargout); |
|
608 done = true; |
|
609 } |
3935
|
610 else if (argc == 2) |
|
611 { |
|
612 std::string arg = argv(1); |
3934
|
613 |
3935
|
614 if (arg == "on" || arg == "off" || arg == "backtrace") |
|
615 { |
|
616 retval = set_warning_option (arg, "", nargout); |
|
617 done = true; |
|
618 } |
|
619 else if (arg == "once" || arg == "always") |
|
620 { |
|
621 retval = set_warning_option ("", arg, nargout); |
|
622 done = true; |
|
623 } |
|
624 else if (arg == "debug") |
|
625 { |
4324
|
626 bind_builtin_variable ("debug_on_warning", true); |
3935
|
627 retval = set_warning_option ("", "", nargout); |
|
628 done = true; |
|
629 } |
|
630 } |
3934
|
631 } |
|
632 } |
|
633 |
3935
|
634 if (! done) |
|
635 { |
|
636 std::string prev_msg = Vlast_warning_message; |
|
637 |
|
638 std::string curr_msg |
|
639 = handle_message (warning, "unspecified warning", args); |
|
640 |
|
641 if (nargout > 0) |
|
642 retval(0) = Vlast_warning_message; |
|
643 } |
|
644 |
3934
|
645 return retval; |
|
646 } |
|
647 |
3935
|
648 DEFUN (lasterr, args, , |
|
649 "-*- texinfo -*-\n\ |
|
650 @deftypefn {Built-in Function} {} lasterr ()\n\ |
|
651 @deftypefnx {Built-in Function} {} lasterr (@var{msg})\n\ |
|
652 Without any arguments, return the last error message. With one\n\ |
|
653 argument, set the last warning message to @var{msg}.\n\ |
|
654 @end deftypefn") |
|
655 { |
|
656 octave_value_list retval; |
|
657 |
|
658 int argc = args.length () + 1; |
|
659 |
|
660 string_vector argv = args.make_argv ("lasterr"); |
|
661 |
|
662 if (argc == 1) |
|
663 retval(0) = Vlast_error_message; |
|
664 else if (argc == 2) |
|
665 Vlast_error_message = argv(1); |
|
666 else |
|
667 print_usage ("lasterr"); |
|
668 |
|
669 return retval; |
|
670 } |
|
671 |
4699
|
672 // For backward compatibility. |
|
673 DEFALIAS (error_text, lasterr); |
|
674 DEFALIAS (__error_text__, lasterr); |
|
675 |
3934
|
676 DEFUN (lastwarn, args, , |
|
677 "-*- texinfo -*-\n\ |
|
678 @deftypefn {Built-in Function} {} lastwarn ()\n\ |
|
679 @deftypefnx {Built-in Function} {} lastwarn (@var{msg})\n\ |
3935
|
680 Without any arguments, return the last warning message. With one\n\ |
|
681 argument, set the last error message to @var{msg}.\n\ |
3934
|
682 @end deftypefn") |
|
683 { |
|
684 octave_value_list retval; |
|
685 |
|
686 int argc = args.length () + 1; |
|
687 |
|
688 string_vector argv = args.make_argv ("lastwarn"); |
|
689 |
|
690 if (argc == 1) |
|
691 retval(0) = Vlast_warning_message; |
|
692 else if (argc == 2) |
|
693 Vlast_warning_message = argv(1); |
|
694 else |
|
695 print_usage ("lastwarn"); |
|
696 |
|
697 return retval; |
897
|
698 } |
|
699 |
1957
|
700 DEFUN (usage, args, , |
3373
|
701 "-*- texinfo -*-\n\ |
|
702 @deftypefn {Built-in Function} {} usage (@var{msg})\n\ |
|
703 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\ |
|
704 set Octave's internal error state such that control will return to the\n\ |
|
705 top level without evaluating any more commands. This is useful for\n\ |
|
706 aborting from functions.\n\ |
|
707 \n\ |
|
708 After @code{usage} is evaluated, Octave will print a traceback of all\n\ |
|
709 the function calls leading to the usage message.\n\ |
899
|
710 \n\ |
3373
|
711 You should use this function for reporting problems errors that result\n\ |
|
712 from an improper call to a function, such as calling a function with an\n\ |
|
713 incorrect number of arguments, or with arguments of the wrong type. For\n\ |
|
714 example, most functions distributed with Octave begin with code like\n\ |
|
715 this\n\ |
|
716 \n\ |
|
717 @example\n\ |
|
718 @group\n\ |
|
719 if (nargin != 2)\n\ |
|
720 usage (\"foo (a, b)\");\n\ |
|
721 endif\n\ |
|
722 @end group\n\ |
|
723 @end example\n\ |
|
724 \n\ |
|
725 @noindent\n\ |
|
726 to check for the proper number of arguments.\n\ |
|
727 @end deftypefn") |
899
|
728 { |
3934
|
729 octave_value_list retval; |
|
730 handle_message (usage, "unknown", args); |
|
731 return retval; |
899
|
732 } |
|
733 |
2174
|
734 static int |
|
735 beep_on_error (void) |
|
736 { |
|
737 Vbeep_on_error = check_preference ("beep_on_error"); |
|
738 |
|
739 return 0; |
|
740 } |
|
741 |
3707
|
742 static int |
|
743 debug_on_error (void) |
|
744 { |
|
745 Vdebug_on_error = check_preference ("debug_on_error"); |
|
746 |
|
747 return 0; |
|
748 } |
|
749 |
|
750 static int |
|
751 debug_on_warning (void) |
|
752 { |
|
753 Vdebug_on_warning = check_preference ("debug_on_warning"); |
|
754 |
|
755 return 0; |
|
756 } |
|
757 |
2174
|
758 void |
|
759 symbols_of_error (void) |
|
760 { |
4233
|
761 DEFVAR (beep_on_error, false, beep_on_error, |
3373
|
762 "-*- texinfo -*-\n\ |
|
763 @defvr {Built-in Variable} beep_on_error\n\ |
|
764 If the value of @code{beep_on_error} is nonzero, Octave will try\n\ |
|
765 to ring your terminal's bell before printing an error message. The\n\ |
|
766 default value is 0.\n\ |
|
767 @end defvr"); |
3018
|
768 |
4233
|
769 DEFVAR (debug_on_error, false, debug_on_error, |
3707
|
770 "-*- texinfo -*-\n\ |
|
771 @defvr {Built-in Variable} debug_on_error\n\ |
|
772 If the value of @code{debug_on_error} is nonzero, Octave will try\n\ |
|
773 to enter the debugger when an error is encountered. This will also\n\ |
|
774 inhibit printing of the normal traceback message (you will only see\n\ |
|
775 the top-level error message). The default value is 0.\n\ |
|
776 @end defvr"); |
|
777 |
4233
|
778 DEFVAR (debug_on_warning, false, debug_on_warning, |
3707
|
779 "-*- texinfo -*-\n\ |
|
780 @defvr {Built-in Variable} debug_on_warning\n\ |
|
781 If the value of @code{debug_on_warning} is nonzero, Octave will try\n\ |
|
782 to enter the debugger when a warning is encountered. The default\n\ |
|
783 value is 0.\n\ |
|
784 @end defvr"); |
2174
|
785 } |
|
786 |
1
|
787 /* |
|
788 ;;; Local Variables: *** |
|
789 ;;; mode: C++ *** |
|
790 ;;; End: *** |
|
791 */ |