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