GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
error.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2017 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cstdarg>
28 #include <cstring>
29 
30 #include <iomanip>
31 #include <iostream>
32 #include <sstream>
33 #include <string>
34 
35 #include "call-stack.h"
36 #include "debug.h"
37 #include "defun.h"
38 #include "error.h"
39 #include "input.h"
40 #include "octave.h"
41 #include "pager.h"
42 #include "ovl.h"
43 #include "oct-map.h"
44 #include "utils.h"
45 #include "ov.h"
46 #include "ov-usr-fcn.h"
47 #include "pt-eval.h"
48 #include "pt-pr-code.h"
49 #include "pt-stmt.h"
50 #include "interpreter.h"
51 #include "unwind-prot.h"
52 #include "variables.h"
53 
54 // TRUE means that Octave will try to beep obnoxiously before printing
55 // error messages.
56 static bool Vbeep_on_error = false;
57 
58 // TRUE means that Octave will try to enter the debugger when an error
59 // is encountered. This will also inhibit printing of the normal
60 // traceback message (you will only see the top-level error message).
61 bool Vdebug_on_error = false;
62 
63 // TRUE means that Octave will try to enter the debugger when an error
64 // is encountered within the 'try' section of a 'try' / 'catch' block.
65 bool Vdebug_on_caught = false;
66 
67 // TRUE means that Octave will try to enter the debugger when a warning
68 // is encountered.
69 bool Vdebug_on_warning = false;
70 
71 // TRUE means that Octave will try to display a stack trace when a
72 // warning is encountered.
73 static bool Vbacktrace_on_warning = true;
74 
75 // TRUE means that Octave will print a verbose warning. Currently unused.
76 static bool Vverbose_warning;
77 
78 // TRUE means that Octave will print no warnings, but lastwarn will be updated
79 static bool Vquiet_warning = false;
80 
81 // A structure containing (most of) the current state of warnings.
83 
84 // The text of the last error message.
86 
87 // The text of the last warning message.
89 
90 // The last warning message id.
92 
93 // The last error message id.
95 
96 // The last file in which an error occurred
98 
99 // Current error state.
100 //
101 // Valid values:
102 //
103 // 0: no error
104 // 1: an error has occurred
105 //
106 int error_state = 0;
107 
108 // Tell the error handler whether to print messages, or just store
109 // them for later. Used for handling errors in eval() and
110 // the 'unwind_protect' statement.
112 
113 // The number of layers of try / catch blocks we're in. Used to print
114 // "caught error" instead of error when "dbstop if caught error" is on.
115 int in_try_catch = 0;
116 
117 // TRUE means error messages are turned off.
119 
120 // TRUE means warning messages are turned off.
122 
123 void
125 {
126  buffer_error_messages = 0;
127  in_try_catch = 0;
128  discard_error_messages = false;
129 }
130 
131 static void
133 {
134  octave_scalar_map initw;
135 
136  initw.setfield ("identifier", "all");
137  initw.setfield ("state", state);
138 
139  warning_options = initw;
140 }
141 
142 static octave_map
144 {
146 }
147 
148 static void
149 verror (bool save_last_error, std::ostream& os,
150  const char *name, const char *id, const char *fmt, va_list args,
151  bool with_cfn = false)
152 {
153  if (discard_error_messages && ! Vdebug_on_caught)
154  return;
155 
156  if (! buffer_error_messages || Vdebug_on_caught)
158 
159  // FIXME: we really want to capture the message before it has all the
160  // formatting goop attached to it. We probably also want just the
161  // message, not the traceback information.
162 
163  std::ostringstream output_buf;
164 
165  octave_vformat (output_buf, fmt, args);
166 
167  std::string base_msg = output_buf.str ();
168 
169  bool to_beep_or_not_to_beep_p = Vbeep_on_error;
170 
171  std::string msg_string;
172 
173  if (to_beep_or_not_to_beep_p)
174  msg_string = "\a";
175 
176  if (name)
177  {
178  if (in_try_catch && ! strcmp (name, "error"))
179  msg_string += "caught error: ";
180  else
181  msg_string += std::string (name) + ": ";
182  }
183 
184  // If with_fcn is specified, we'll attempt to prefix the message with the name
185  // of the current executing function. But we'll do so only if:
186  // 1. the name is not empty (anonymous function)
187  // 2. it is not already there (including the following colon)
188  if (with_cfn)
189  {
191  if (curfcn)
192  {
193  std::string cfn = curfcn->name ();
194  if (! cfn.empty ())
195  {
196  cfn += ':';
197  if (cfn.length () > base_msg.length ()
198  || base_msg.compare (0, cfn.length (), cfn) != 0)
199  {
200  msg_string += cfn + ' ';
201  }
202  }
203  }
204  }
205 
206  msg_string += base_msg + "\n";
207 
208  if (save_last_error)
209  {
210  // This is the first error in a possible series.
211 
212  Vlast_error_id = id;
213  Vlast_error_message = base_msg;
214 
216 
217  if (fcn)
218  {
219  octave_idx_type curr_frame = -1;
220 
221  Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame);
222  }
223  else
224  Vlast_error_stack = initialize_last_error_stack ();
225  }
226 
227  if (! buffer_error_messages || Vdebug_on_caught)
228  {
229  octave_diary << msg_string;
230  os << msg_string;
231  }
232 }
233 
234 static void
235 pr_where_2 (std::ostream& os, const char *fmt, va_list args)
236 {
237  if (fmt)
238  {
239  if (*fmt)
240  {
241  size_t len = strlen (fmt);
242 
243  if (len > 0)
244  {
245  if (fmt[len - 1] == '\n')
246  {
247  if (len > 1)
248  {
249  std::string tmp_fmt (fmt, len - 1);
250  verror (false, os, 0, "", tmp_fmt.c_str (), args);
251  }
252  }
253  else
254  verror (false, os, 0, "", fmt, args);
255  }
256  }
257  }
258  else
259  panic ("pr_where_2: invalid format");
260 }
261 
262 static void
263 pr_where_1 (std::ostream& os, const char *fmt, ...)
264 {
265  va_list args;
266  va_start (args, fmt);
267  pr_where_2 (os, fmt, args);
268  va_end (args);
269 }
270 
271 struct
273 {
275  int line;
276  int column;
277 };
278 
279 static void
280 pr_where (std::ostream& os, const char *who,
281  const std::list<error_stack_frame>& frames)
282 {
283  size_t nframes = frames.size ();
284 
285  if (nframes > 0)
286  pr_where_1 (os, "%s: called from\n", who);
287 
288  for (std::list<error_stack_frame>::const_iterator p = frames.begin ();
289  p != frames.end (); p++)
290  {
291  const error_stack_frame& elt = *p;
292 
293  std::string fcn_name = elt.name;
294  int line = elt.line;
295  int column = elt.column;
296 
297  if (line > 0)
298  {
299  if (column > 0)
300  pr_where_1 (os, " %s at line %d column %d\n",
301  fcn_name.c_str (), line, column);
302  else
303  pr_where_1 (os, " %s at line %d\n", fcn_name.c_str (), line);
304  }
305  else
306  pr_where_1 (os, " %s\n", fcn_name.c_str ());
307  }
308 }
309 
310 static void
311 pr_where (std::ostream& os, const char *who)
312 {
313  std::list<octave_call_stack::stack_frame> call_stack_frames
315 
316  // Print the error message only if it is different from the previous one;
317  // Makes the output more concise and readable.
318  call_stack_frames.unique ();
319 
320  std::list<error_stack_frame> frames;
321  for (std::list<octave_call_stack::stack_frame>::const_iterator p = call_stack_frames.begin ();
322  p != call_stack_frames.end (); p++)
323  {
324  const octave_call_stack::stack_frame& elt = *p;
325 
327 
328  frame.name = elt.fcn_name ();
329  frame.line = elt.line ();
330  frame.column = elt.column ();
331 
332  frames.push_back (frame);
333  }
334 
335  pr_where (os, who, frames);
336 }
337 
338 static octave::execution_exception
339 make_execution_exception (const char *who)
340 {
341  std::ostringstream buf;
342 
343  pr_where (buf, who);
344 
345  octave::execution_exception retval;
346 
347  retval.set_stack_trace (buf.str ());
348 
349  return retval;
350 }
351 
352 static void
353 maybe_enter_debugger (octave::execution_exception& e,
354  bool show_stack_trace = false)
355 {
356  if ((octave::application::interactive ()
357  || octave::application::forced_interactive ())
358  && ((Vdebug_on_error && bp_table::debug_on_err (last_error_id ()))
359  || (Vdebug_on_caught && bp_table::debug_on_caught (last_error_id ())))
361  {
363  frame.protect_var (Vdebug_on_error);
364  Vdebug_on_error = false;
365 
367 
369 
370  if (show_stack_trace)
371  {
372  std::string stack_trace = e.info ();
373 
374  if (! stack_trace.empty ())
375  {
376  std::cerr << stack_trace;
377 
378  e.set_stack_trace ();
379  }
380  }
381 
383  }
384 }
385 
386 // Warning messages are never buffered.
387 
388 static void
389 vwarning (const char *name, const char *id, const char *fmt, va_list args)
390 {
391  if (discard_warning_messages)
392  return;
393 
395 
396  std::ostringstream output_buf;
397 
398  octave_vformat (output_buf, fmt, args);
399 
400  // FIXME: we really want to capture the message before it has all the
401  // formatting goop attached to it. We probably also want just the
402  // message, not the traceback information.
403 
404  std::string base_msg = output_buf.str ();
405  std::string msg_string;
406 
407  if (name)
408  msg_string = std::string (name) + ": ";
409 
410  msg_string += base_msg + "\n";
411 
413  Vlast_warning_message = base_msg;
414 
415  if (! Vquiet_warning)
416  {
417  octave_diary << msg_string;
418 
419  std::cerr << msg_string;
420  }
421 }
422 
423 void
424 vmessage (const char *name, const char *fmt, va_list args)
425 {
426  verror (false, std::cerr, name, "", fmt, args);
427 }
428 
429 void
430 message (const char *name, const char *fmt, ...)
431 {
432  va_list args;
433  va_start (args, fmt);
434  vmessage (name, fmt, args);
435  va_end (args);
436 }
437 
438 void
439 vmessage_with_id (const char *name, const char *id, const char *fmt,
440  va_list args)
441 {
442  verror (false, std::cerr, name, id, fmt, args);
443 }
444 
445 void
446 message_with_id (const char *name, const char *id, const char *fmt, ...)
447 {
448  va_list args;
449  va_start (args, fmt);
450  vmessage_with_id (name, id, fmt, args);
451  va_end (args);
452 }
453 
454 OCTAVE_NORETURN static
455 void
456 usage_1 (octave::execution_exception& e, const char *id,
457  const char *fmt, va_list args)
458 {
459  verror (true, std::cerr, "usage", id, fmt, args);
460 
462 
463  throw e;
464 }
465 
466 OCTAVE_NORETURN static
467 void
468 usage_1 (const char *id, const char *fmt, va_list args)
469 {
470  octave::execution_exception e = make_execution_exception ("usage");
471 
472  usage_1 (e, id, fmt, args);
473 }
474 
475 void
476 vusage (const char *fmt, va_list args)
477 {
478  usage_1 ("", fmt, args);
479 }
480 
481 void
482 usage (const char *fmt, ...)
483 {
484  va_list args;
485  va_start (args, fmt);
486  usage_1 ("", fmt, args);
487  va_end (args);
488 }
489 
490 void
491 vusage_with_id (const char *id, const char *fmt, va_list args)
492 {
493  usage_1 (id, fmt, args);
494 }
495 
496 void
497 usage_with_id (const char *id, const char *fmt, ...)
498 {
499  va_list args;
500  va_start (args, fmt);
501  vusage_with_id (id, fmt, args);
502  va_end (args);
503 }
504 
505 OCTAVE_NORETURN static
506 void
507 error_1 (octave::execution_exception& e, std::ostream& os,
508  const char *name, const char *id, const char *fmt,
509  va_list args, bool with_cfn = false)
510 {
511  bool show_stack_trace = false;
512 
513  if (fmt)
514  {
515  if (*fmt)
516  {
517  size_t len = strlen (fmt);
518 
519  if (len > 0)
520  {
521  if (fmt[len - 1] == '\n')
522  {
523  if (len > 1)
524  {
525  std::string tmp_fmt (fmt, len - 1);
526  verror (true, os, name, id, tmp_fmt.c_str (),
527  args, with_cfn);
528  }
529 
530  // If format ends with newline, suppress stack trace.
531  e.set_stack_trace ();
532  }
533  else
534  {
535  verror (true, os, name, id, fmt, args, with_cfn);
536 
537  bool in_user_code = octave_call_stack::caller_user_code () != 0;
538 
539  if (in_user_code && ! discard_error_messages)
540  show_stack_trace = true;
541  }
542  }
543  }
544  }
545  else
546  panic ("error_1: invalid format");
547 
548  maybe_enter_debugger (e, show_stack_trace);
549 
550  throw e;
551 }
552 
553 OCTAVE_NORETURN static
554 void
555 error_1 (std::ostream& os, const char *name, const char *id,
556  const char *fmt, va_list args, bool with_cfn = false)
557 {
558  octave::execution_exception e = make_execution_exception ("error");
559 
560  error_1 (e, os, name, id, fmt, args, with_cfn);
561 }
562 
563 void
564 verror (const char *fmt, va_list args)
565 {
566  error_1 (std::cerr, "error", "", fmt, args);
567 }
568 
569 void
570 error (const char *fmt, ...)
571 {
572  va_list args;
573  va_start (args, fmt);
574  verror (fmt, args);
575  va_end (args);
576 }
577 
578 void
579 verror (octave::execution_exception& e, const char *fmt, va_list args)
580 {
581  error_1 (e, std::cerr, "error", "", fmt, args);
582 }
583 
584 void
585 error (octave::execution_exception& e, const char *fmt, ...)
586 {
587  va_list args;
588  va_start (args, fmt);
589  verror (e, fmt, args);
590  va_end (args);
591 }
592 
593 void
594 verror_with_cfn (const char *fmt, va_list args)
595 {
596  error_1 (std::cerr, "error", "", fmt, args, true);
597 }
598 
599 void
600 error_with_cfn (const char *fmt, ...)
601 {
602  va_list args;
603  va_start (args, fmt);
604  verror_with_cfn (fmt, args);
605  va_end (args);
606 }
607 
608 void
609 verror_with_id (const char *id, const char *fmt, va_list args)
610 {
611  error_1 (std::cerr, "error", id, fmt, args);
612 }
613 
614 void
615 error_with_id (const char *id, const char *fmt, ...)
616 {
617  va_list args;
618  va_start (args, fmt);
619  verror_with_id (id, fmt, args);
620  va_end (args);
621 }
622 
623 void
624 verror_with_id_cfn (const char *id, const char *fmt, va_list args)
625 {
626  error_1 (std::cerr, "error", id, fmt, args, true);
627 }
628 
629 void
630 error_with_id_cfn (const char *id, const char *fmt, ...)
631 {
632  va_list args;
633  va_start (args, fmt);
634  verror_with_id_cfn (id, fmt, args);
635  va_end (args);
636 }
637 
638 static int
640 {
641  // -1: not found
642  // 0: found, "off"
643  // 1: found, "on"
644  // 2: found, "error"
645 
646  if (state == "off")
647  return 0;
648  else if (state == "on")
649  return 1;
650  else if (state == "error")
651  return 2;
652  else
653  return -1;
654 }
655 
656 // For given warning ID, return 0 if warnings are disabled, 1 if
657 // enabled, and 2 if the given ID should be an error instead of a
658 // warning.
659 
660 int
662 {
663  int retval = 0;
664 
665  int all_state = -1;
666  int id_state = -1;
667 
668  octave_idx_type nel = warning_options.numel ();
669 
670  if (nel > 0)
671  {
672  Cell identifier = warning_options.contents ("identifier");
673  Cell state = warning_options.contents ("state");
674 
675  bool all_found = false;
676  bool id_found = false;
677 
678  for (octave_idx_type i = 0; i < nel; i++)
679  {
680  octave_value ov = identifier(i);
681  std::string ovs = ov.string_value ();
682 
683  if (! all_found && ovs == "all")
684  {
685  all_state = check_state (state(i).string_value ());
686 
687  if (all_state >= 0)
688  all_found = true;
689  }
690 
691  if (! id_found && ovs == id)
692  {
693  id_state = check_state (state(i).string_value ());
694 
695  if (id_state >= 0)
696  id_found = true;
697  }
698 
699  if (all_found && id_found)
700  break;
701  }
702  }
703 
704  // If "all" is not present, assume warnings are enabled.
705  if (all_state == -1)
706  all_state = 1;
707 
708  if (all_state == 0)
709  {
710  if (id_state >= 0)
711  retval = id_state;
712  }
713  else if (all_state == 1)
714  {
715  if (id_state == 0 || id_state == 2)
716  retval = id_state;
717  else
718  retval = all_state;
719  }
720  else if (all_state == 2)
721  {
722  if (id_state == 0)
723  retval= id_state;
724  else
725  retval = all_state;
726  }
727 
728  return retval;
729 }
730 
731 static void
732 warning_1 (const char *id, const char *fmt, va_list args)
733 {
734  int warn_opt = warning_enabled (id);
735 
736  if (warn_opt == 2)
737  {
738  // Handle this warning as an error.
739 
740  error_1 (std::cerr, "error", id, fmt, args);
741  }
742  else if (warn_opt == 1)
743  {
744  bool fmt_suppresses_backtrace = false;
745  size_t fmt_len = fmt ? strlen (fmt) : 0;
746  fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n');
747 
748  if (fmt_suppresses_backtrace && fmt_len > 1)
749  {
750  // Strip newline before issuing warning
751  std::string tmp_fmt (fmt, fmt_len - 1);
752  vwarning ("warning", id, tmp_fmt.c_str (), args);
753  }
754  else
755  vwarning ("warning", id, fmt, args);
756 
757  bool in_user_code = octave_call_stack::caller_user_code () != 0;
758 
759  if (! fmt_suppresses_backtrace && in_user_code
760  && Vbacktrace_on_warning
761  && ! discard_warning_messages)
762  pr_where (std::cerr, "warning");
763 
764  if ((octave::application::interactive ()
765  || octave::application::forced_interactive ())
766  && Vdebug_on_warning && in_user_code && bp_table::debug_on_warn (id))
767  {
769  frame.protect_var (Vdebug_on_warning);
770  Vdebug_on_warning = false;
771 
773 
775 
777  }
778  }
779 }
780 
781 void
782 vwarning (const char *fmt, va_list args)
783 {
784  warning_1 ("", fmt, args);
785 }
786 
787 void
788 warning (const char *fmt, ...)
789 {
790  va_list args;
791  va_start (args, fmt);
792  vwarning (fmt, args);
793  va_end (args);
794 }
795 
796 void
797 vwarning_with_id (const char *id, const char *fmt, va_list args)
798 {
799  warning_1 (id, fmt, args);
800 }
801 
802 void
803 warning_with_id (const char *id, const char *fmt, ...)
804 {
805  va_list args;
806  va_start (args, fmt);
807  vwarning_with_id (id, fmt, args);
808  va_end (args);
809 }
810 
811 void
812 vparse_error (const char *fmt, va_list args)
813 {
814  error_1 (std::cerr, 0, "", fmt, args);
815 }
816 
817 void
818 parse_error (const char *fmt, ...)
819 {
820  va_list args;
821  va_start (args, fmt);
822  vparse_error (fmt, args);
823  va_end (args);
824 }
825 
826 void
827 vparse_error_with_id (const char *id, const char *fmt, va_list args)
828 {
829  error_1 (std::cerr, 0, id, fmt, args);
830 }
831 
832 void
833 parse_error_with_id (const char *id, const char *fmt, ...)
834 {
835  va_list args;
836  va_start (args, fmt);
837  vparse_error_with_id (id, fmt, args);
838  va_end (args);
839 }
840 
841 void
842 rethrow_error (const char *id, const char *fmt, ...)
843 {
844  va_list args;
845  va_start (args, fmt);
846  error_1 (std::cerr, 0, id, fmt, args);
847  va_end (args);
848 }
849 
850 static std::list<error_stack_frame>
852 {
853  std::list<error_stack_frame> frames;
854 
855  Cell name = stack.contents ("name");
856  Cell line = stack.contents ("line");
857  Cell column;
858  bool have_column = false;
859  if (stack.contains ("column"))
860  {
861  have_column = true;
862  column = stack.contents ("column");
863  }
864 
865  octave_idx_type nel = name.numel ();
866 
867  for (octave_idx_type i = 0; i < nel; i++)
868  {
870 
871  frame.name = name(i).string_value ();
872  frame.line = line(i).int_value ();
873  frame.column = have_column ? column(i).int_value () : -1;
874 
875  frames.push_back (frame);
876  }
877 
878  return frames;
879 }
880 
881 static void
882 rethrow_error_1 (const char *id, const char *fmt, ...)
883 {
884  va_list args;
885  va_start (args, fmt);
886  verror (false, std::cerr, 0, id, fmt, args);
887  va_end (args);
888 }
889 
890 OCTAVE_NORETURN static
891 void
892 rethrow_error (const std::string& id, const std::string& msg,
893  const octave_map& stack)
894 {
895  octave::execution_exception e = make_execution_exception ("error");
896 
897  if (! stack.is_empty ()
898  && ! (stack.contains ("file") && stack.contains ("name")
899  && stack.contains ("line")))
900  error ("rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
901 
902  Vlast_error_id = id;
903  Vlast_error_message = msg;
904  Vlast_error_stack = stack;
905 
906  size_t len = msg.length ();
907 
908  std::string tmp_msg (msg);
909  if (len > 1 && tmp_msg[len-1] == '\n')
910  {
911  tmp_msg.erase (len - 1);
912 
913  rethrow_error_1 (id.c_str (), "%s\n", tmp_msg.c_str ());
914  }
915  else
916  rethrow_error_1 (id.c_str (), "%s", tmp_msg.c_str ());
917 
918  if (! stack.is_empty ())
919  {
920  std::ostringstream buf;
921 
922  pr_where (buf, "error", make_stack_frame_list (stack));
923 
924  e.set_stack_trace (buf.str ());
925  }
926 
927  throw e;
928 }
929 
930 void
931 panic (const char *fmt, ...)
932 {
933  va_list args;
934  va_start (args, fmt);
935  buffer_error_messages = 0;
936  discard_error_messages = false;
937  verror (false, std::cerr, "panic", "", fmt, args);
938  va_end (args);
939  abort ();
940 }
941 
942 static void
943 defun_usage_message_1 (const char *fmt, ...)
944 {
945  va_list args;
946  va_start (args, fmt);
947  error_1 (octave_stdout, 0, "", fmt, args);
948  va_end (args);
949 }
950 
951 void
953 {
954  defun_usage_message_1 ("%s", msg.c_str ());
955 }
956 
957 typedef void (*error_fun)(const char *, const char *, ...);
958 
959 extern octave_value_list Fsprintf (const octave_value_list&, int);
960 
961 static std::string
962 handle_message (error_fun f, const char *id, const char *msg,
963  const octave_value_list& args, bool have_fmt)
964 {
966 
967  std::string tstr;
968 
969  if (args.length () > 0)
970  {
972 
973  if (have_fmt)
974  {
975  octave_value_list tmp = Fsprintf (args, 1);
976  arg = tmp(0);
977  }
978  else
979  arg = args(0);
980 
981  if (arg.is_defined ())
982  {
983  if (arg.is_string ())
984  {
985  tstr = arg.string_value ();
986  msg = tstr.c_str ();
987 
988  if (! msg)
989  return retval;
990  }
991  else if (arg.is_empty ())
992  return retval;
993  }
994  }
995 
996 // Ugh.
997 
998  size_t len = strlen (msg);
999 
1000  if (len > 0)
1001  {
1002  if (msg[len - 1] == '\n')
1003  {
1004  if (len > 1)
1005  {
1006  std::string tmp_msg (msg, len - 1);
1007  f (id, "%s\n", tmp_msg.c_str ());
1008  retval = tmp_msg;
1009  }
1010  }
1011  else
1012  {
1013  f (id, "%s", msg);
1014  retval = msg;
1015  }
1016  }
1017 
1018  return retval;
1019 }
1020 
1021 DEFUN (rethrow, args, ,
1022  doc: /* -*- texinfo -*-
1023 @deftypefn {} {} rethrow (@var{err})
1024 Reissue a previous error as defined by @var{err}.
1025 
1026 @var{err} is a structure that must contain at least the @qcode{"message"}
1027 and @qcode{"identifier"} fields. @var{err} can also contain a field
1028 @qcode{"stack"} that gives information on the assumed location of the
1029 error. Typically @var{err} is returned from @code{lasterror}.
1030 @seealso{lasterror, lasterr, error}
1031 @end deftypefn */)
1032 {
1033  if (args.length () != 1)
1034  print_usage ();
1035 
1036  const octave_scalar_map err = args(0).scalar_map_value ();
1037 
1038  if (! (err.contains ("message") && err.contains ("identifier")))
1039  error ("rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1040 
1041  std::string msg = err.contents ("message").string_value ();
1042  std::string id = err.contents ("identifier").string_value ();
1043 
1044  octave_map err_stack = initialize_last_error_stack ();
1045 
1046  if (err.contains ("stack"))
1047  err_stack = err.contents ("stack").xmap_value ("ERR.STACK must be a struct");
1048 
1049  rethrow_error (id, msg, err_stack);
1050 
1051  return ovl ();
1052 }
1053 
1054 // Determine whether the first argument to error or warning function
1055 // should be handled as the message identifier or as the format string.
1056 
1057 static bool
1058 maybe_extract_message_id (const std::string& caller,
1059  const octave_value_list& args,
1060  octave_value_list& nargs,
1061  std::string& id)
1062 {
1063  nargs = args;
1064  id = "";
1065 
1066  int nargin = args.length ();
1067 
1068  bool have_fmt = nargin > 1;
1069 
1070  if (nargin > 0)
1071  {
1072  std::string arg1 = args(0).string_value ();
1073 
1074  // For compatibility with Matlab, an identifier must contain
1075  // ':', but not at the beginning or the end, and it must not
1076  // contain '%' (even if it is not a valid conversion
1077  // operator) or whitespace.
1078 
1079  if (arg1.find_first_of ("% \f\n\r\t\v") == std::string::npos
1080  && arg1.find (':') != std::string::npos
1081  && arg1[0] != ':'
1082  && arg1[arg1.length ()-1] != ':')
1083  {
1084  if (nargin > 1)
1085  {
1086  id = arg1;
1087 
1088  nargs.resize (nargin-1);
1089 
1090  for (int i = 1; i < nargin; i++)
1091  nargs(i-1) = args(i);
1092  }
1093  else
1094  nargs(0) = "call to " + caller
1095  + " with message identifier '" + arg1
1096  + "' requires message";
1097  }
1098  }
1099 
1100  return have_fmt;
1101 }
1102 
1103 DEFUN (error, args, ,
1104  doc: /* -*- texinfo -*-
1105 @deftypefn {} {} error (@var{template}, @dots{})
1106 @deftypefnx {} {} error (@var{id}, @var{template}, @dots{})
1107 Display an error message and stop m-file execution.
1108 
1109 Format the optional arguments under the control of the template string
1110 @var{template} using the same rules as the @code{printf} family of
1111 functions (@pxref{Formatted Output}) and print the resulting message
1112 on the @code{stderr} stream. The message is prefixed by the character
1113 string @samp{error: }.
1114 
1115 Calling @code{error} also sets Octave's internal error state such that
1116 control will return to the top level without evaluating any further
1117 commands. This is useful for aborting from functions or scripts.
1118 
1119 If the error message does not end with a newline character, Octave will
1120 print a traceback of all the function calls leading to the error. For
1121 example, given the following function definitions:
1122 
1123 @example
1124 @group
1125 function f () g (); end
1126 function g () h (); end
1127 function h () nargin == 1 || error ("nargin != 1"); end
1128 @end group
1129 @end example
1130 
1131 @noindent
1132 calling the function @code{f} will result in a list of messages that
1133 can help you to quickly find the exact location of the error:
1134 
1135 @example
1136 @group
1137 f ()
1138 error: nargin != 1
1139 error: called from:
1140 error: h at line 1, column 27
1141 error: g at line 1, column 15
1142 error: f at line 1, column 15
1143 @end group
1144 @end example
1145 
1146 If the error message ends in a newline character, Octave will print the
1147 message but will not display any traceback messages as it returns
1148 control to the top level. For example, modifying the error message
1149 in the previous example to end in a newline causes Octave to only print
1150 a single message:
1151 
1152 @example
1153 @group
1154 function h () nargin == 1 || error ("nargin != 1\n"); end
1155 f ()
1156 error: nargin != 1
1157 @end group
1158 @end example
1159 
1160 A null string ("") input to @code{error} will be ignored and the code
1161 will continue running as if the statement were a NOP@. This is for
1162 compatibility with @sc{matlab}. It also makes it possible to write code
1163 such as
1164 
1165 @example
1166 @group
1167 err_msg = "";
1168 if (CONDITION 1)
1169  err_msg = "CONDITION 1 found";
1170 elseif (CONDITION2)
1171  err_msg = "CONDITION 2 found";
1172 @dots{}
1173 endif
1174 error (err_msg);
1175 @end group
1176 @end example
1177 
1178 @noindent
1179 which will only stop execution if an error has been found.
1180 
1181 Implementation Note: For compatibility with @sc{matlab}, escape
1182 sequences in @var{template} (e.g., @qcode{"@xbackslashchar{}n"} =>
1183 newline) are processed regardless of whether @var{template} has been defined
1184 with single quotes, as long as there are two or more input arguments. To
1185 disable escape sequence expansion use a second backslash before the sequence
1186 (e.g., @qcode{"@xbackslashchar{}@xbackslashchar{}n"}) or use the
1187 @code{regexptranslate} function.
1188 @seealso{warning, lasterror}
1189 @end deftypefn */)
1190 {
1191 
1192  int nargin = args.length ();
1193 
1194  if (nargin == 0)
1195  print_usage ();
1196 
1198 
1199  octave_value_list nargs = args;
1200 
1201  std::string id;
1202 
1203  bool have_fmt = false;
1204 
1205  if (nargin == 1 && args(0).is_map ())
1206  {
1207  // empty struct is not an error. return and resume calling function.
1208  if (args(0).is_empty ())
1209  return retval;
1210 
1211  octave_scalar_map m = args(0).scalar_map_value ();
1212 
1213  // empty struct is not an error. return and resume calling function.
1214  if (m.nfields () == 0)
1215  return retval;
1216 
1217  if (m.contains ("message"))
1218  {
1219  octave_value c = m.getfield ("message");
1220 
1221  if (c.is_string ())
1222  nargs(0) = c.string_value ();
1223  }
1224 
1225  if (m.contains ("identifier"))
1226  {
1227  octave_value c = m.getfield ("identifier");
1228 
1229  if (c.is_string ())
1230  id = c.string_value ();
1231  }
1232 
1233  // FIXME: also need to handle "stack" field in error structure,
1234  // but that will require some more significant surgery on
1235  // handle_message, error_with_id, etc.
1236  }
1237  else
1238  have_fmt = maybe_extract_message_id ("error", args, nargs, id);
1239 
1240  handle_message (error_with_id, id.c_str (), "unspecified error",
1241  nargs, have_fmt);
1242 
1243  return retval;
1244 }
1245 
1246 static octave_scalar_map
1247 warning_query (const std::string& id_arg)
1248 {
1250 
1251  std::string id = id_arg;
1252 
1253  if (id == "last")
1254  id = Vlast_warning_id;
1255 
1256  Cell ident = warning_options.contents ("identifier");
1257  Cell state = warning_options.contents ("state");
1258 
1259  octave_idx_type nel = ident.numel ();
1260 
1261  assert (nel != 0);
1262 
1263  bool found = false;
1264 
1265  std::string val;
1266 
1267  for (octave_idx_type i = 0; i < nel; i++)
1268  {
1269  if (ident(i).string_value () == id)
1270  {
1271  val = state(i).string_value ();
1272  found = true;
1273  break;
1274  }
1275  }
1276 
1277  if (! found)
1278  {
1279  for (octave_idx_type i = 0; i < nel; i++)
1280  {
1281  if (ident(i).string_value () == "all")
1282  {
1283  val = state(i).string_value ();
1284  found = true;
1285  break;
1286  }
1287  }
1288  }
1289 
1290  // The warning state "all" is always supposed to remain in the list,
1291  // so we should always find a state, either explicitly or by using the
1292  // state for "all".
1293 
1294  assert (found);
1295 
1296  retval.assign ("identifier", id);
1297  retval.assign ("state", val);
1298 
1299  return retval;
1300 }
1301 
1302 static std::string
1303 default_warning_state (void)
1304 {
1305  std::string retval = "on";
1306 
1307  Cell ident = warning_options.contents ("identifier");
1308  Cell state = warning_options.contents ("state");
1309 
1310  octave_idx_type nel = ident.numel ();
1311 
1312  for (octave_idx_type i = 0; i < nel; i++)
1313  {
1314  if (ident(i).string_value () == "all")
1315  {
1316  retval = state(i).string_value ();
1317  break;
1318  }
1319  }
1320 
1321  return retval;
1322 }
1323 
1324 static void
1325 display_warning_options (std::ostream& os)
1326 {
1327  Cell ident = warning_options.contents ("identifier");
1328  Cell state = warning_options.contents ("state");
1329 
1330  octave_idx_type nel = ident.numel ();
1331 
1332  std::string all_state = default_warning_state ();
1333 
1334  if (all_state == "on")
1335  os << "By default, warnings are enabled.";
1336  else if (all_state == "off")
1337  os << "By default, warnings are disabled.";
1338  else if (all_state == "error")
1339  os << "By default, warnings are treated as errors.";
1340  else
1341  panic_impossible ();
1342 
1343  if (nel > 1)
1344  os << "\n\n";
1345 
1346  // The state for all is always supposed to be first in the list.
1347 
1348  for (octave_idx_type i = 1; i < nel; i++)
1349  {
1350  std::string tid = ident(i).string_value ();
1351  std::string tst = state(i).string_value ();
1352 
1353  os << std::setw (7) << tst << " " << tid << "\n";
1354  }
1355 
1356  os << std::endl;
1357 }
1358 
1359 static void
1360 set_warning_option (const std::string& state, const std::string& ident)
1361 {
1362  std::string all_state = default_warning_state ();
1363 
1364  if (state != "on" && state != "off" && state != "error")
1365  error ("invalid warning state: %s", state.c_str ());
1366 
1367  Cell tid = warning_options.contents ("identifier");
1368  Cell tst = warning_options.contents ("state");
1369 
1370  octave_idx_type nel = tid.numel ();
1371 
1372  for (octave_idx_type i = 0; i < nel; i++)
1373  {
1374  if (tid(i).string_value () == ident)
1375  {
1376  // We found it in the current list of options. If the state
1377  // for "all" is same as arg1, we can simply remove the item
1378  // from the list.
1379 
1380  if (state == all_state && ident != "all")
1381  {
1382  for (i = i + 1; i < nel; i++)
1383  {
1384  tid(i-1) = tid(i);
1385  tst(i-1) = tst(i);
1386  }
1387 
1388  tid.resize (dim_vector (1, nel-1));
1389  tst.resize (dim_vector (1, nel-1));
1390  }
1391  else
1392  tst(i) = state;
1393 
1394  warning_options.clear ();
1395 
1396  warning_options.assign ("identifier", tid);
1397  warning_options.assign ("state", tst);
1398 
1399  return;
1400  }
1401  }
1402 
1403  // The option wasn't already in the list. Append it.
1404 
1405  tid.resize (dim_vector (1, nel+1));
1406  tst.resize (dim_vector (1, nel+1));
1407 
1408  tid(nel) = ident;
1409  tst(nel) = state;
1410 
1411  warning_options.clear ();
1412 
1413  warning_options.assign ("identifier", tid);
1414  warning_options.assign ("state", tst);
1415 }
1416 
1417 DEFUN (warning, args, nargout,
1418  doc: /* -*- texinfo -*-
1419 @deftypefn {} {} warning (@var{template}, @dots{})
1420 @deftypefnx {} {} warning (@var{id}, @var{template}, @dots{})
1421 @deftypefnx {} {} warning ("on", @var{id})
1422 @deftypefnx {} {} warning ("off", @var{id})
1423 @deftypefnx {} {} warning ("query", @var{id})
1424 @deftypefnx {} {} warning ("error", @var{id})
1425 @deftypefnx {} {} warning (@var{state}, "backtrace")
1426 @deftypefnx {} {} warning (@var{state}, @var{id}, "local")
1427 Display a warning message or control the behavior of Octave's warning
1428 system.
1429 
1430 Format the optional arguments under the control of the template string
1431 @var{template} using the same rules as the @code{printf} family of
1432 functions (@pxref{Formatted Output}) and print the resulting message
1433 on the @code{stderr} stream. The message is prefixed by the character
1434 string @samp{warning: }.
1435 You should use this function when you want to notify the user
1436 of an unusual condition, but only when it makes sense for your program
1437 to go on.
1438 
1439 The optional message identifier allows users to enable or disable
1440 warnings tagged by @var{id}. A message identifier is of the form
1441 "NAMESPACE:WARNING-NAME". Octave's own warnings use the
1442 @qcode{"Octave"} namespace (@pxref{XREFwarning_ids}). The special
1443 identifier @qcode{"all"} may be used to set the state of all warnings.
1444 
1445 If the first argument is @qcode{"on"} or @qcode{"off"},
1446 set the state of a particular warning using the identifier @var{id}. If the
1447 first argument is @qcode{"query"}, query the state of this warning
1448 instead. If the identifier is omitted, a value of @qcode{"all"} is
1449 assumed. If you set the state of a warning to @qcode{"error"}, the
1450 warning named by @var{id} is handled as if it were an error instead. So,
1451 for example, the following handles all warnings as errors:
1452 
1453 @example
1454 @group
1455 warning ("error");
1456 @end group
1457 @end example
1458 
1459 If the state is @qcode{"on"} or @qcode{"off"} and the third argument
1460 is @qcode{"backtrace"}, then a stack trace is printed along with the
1461 warning message when warnings occur inside function calls. This option
1462 is enabled by default.
1463 
1464 If the state is @qcode{"on"}, @qcode{"off"}, or @qcode{"error"}
1465 and the third argument is @qcode{"local"}, then the warning state
1466 will be set temporarily, until the end of the current function.
1467 Changes to warning states that are set locally affect the current
1468 function and all functions called from the current scope. The
1469 previous warning state is restored on return from the current
1470 function. The @qcode{"local"} option is ignored if used in the top-level
1471 workspace.
1472 
1473 Implementation Note: For compatibility with @sc{matlab}, escape
1474 sequences in @var{template} (e.g., @qcode{"@xbackslashchar{}n"} =>
1475 newline) are processed regardless of whether @var{template} has been defined
1476 with single quotes, as long as there are two or more input arguments. To
1477 disable escape sequence expansion use a second backslash before the sequence
1478 (e.g., @qcode{"@xbackslashchar{}@xbackslashchar{}n"}) or use the
1479 @code{regexptranslate} function.
1480 @seealso{warning_ids, lastwarn, error}
1481 @end deftypefn */)
1482 {
1484 
1485  int nargin = args.length ();
1486  bool done = false;
1487 
1488  if (nargin > 0 && args.all_strings_p ())
1489  {
1490  string_vector argv = args.make_argv ("warning");
1491 
1492  std::string arg1 = argv[1];
1493  std::string arg2 = "all";
1494 
1495  if (nargin >= 2)
1496  arg2 = argv[2];
1497 
1498  if (arg1 == "on" || arg1 == "off" || arg1 == "error")
1499  {
1500  octave_map old_warning_options = warning_options;
1501 
1502  if (nargin == 3 && argv[3] == "local"
1504  {
1507 
1510 
1511  octave_scalar_map val = warning_query (arg2);
1512 
1513  octave_value curr_state = val.contents ("state");
1514 
1515  // FIXME: this might be better with a dictionary object.
1516 
1517  octave_value curr_warning_states
1518  = symbol_table::varval (".saved_warning_states.",
1519  scope, context);
1520 
1521  octave_map m;
1522 
1523  if (curr_warning_states.is_defined ())
1524  m = curr_warning_states.map_value ();
1525  else
1526  {
1527  string_vector fields (2);
1528 
1529  fields(0) = "identifier";
1530  fields(1) = "state";
1531 
1532  m = octave_map (dim_vector (0, 1), fields);
1533  }
1534 
1535  Cell ids = m.contents ("identifier");
1536  Cell states = m.contents ("state");
1537 
1538  octave_idx_type nel = states.numel ();
1539  bool found = false;
1541  for (i = 0; i < nel; i++)
1542  {
1543  std::string id = ids(i).string_value ();
1544 
1545  if (id == arg2)
1546  {
1547  states(i) = curr_state;
1548  found = true;
1549  break;
1550  }
1551  }
1552 
1553  if (! found)
1554  {
1555  m.resize (dim_vector (nel+1, 1));
1556 
1557  ids.resize (dim_vector (nel+1, 1));
1558  states.resize (dim_vector (nel+1, 1));
1559 
1560  ids(nel) = arg2;
1561  states(nel) = curr_state;
1562  }
1563 
1564  m.contents ("identifier") = ids;
1565  m.contents ("state") = states;
1566 
1567  symbol_table::assign (".saved_warning_states.",
1568  m, scope, context);
1569 
1570  // Now ignore the "local" argument and continue to
1571  // handle the current setting.
1572  nargin--;
1573  }
1574 
1575  if (nargin >= 2 && arg2 == "all")
1576  {
1577  // If "all" is explicitly given as ID.
1578 
1579  octave_map tmp;
1580  int is_error = (arg1 == "error");
1581 
1582  Cell id (1, 1 + 2*is_error);
1583  Cell st (1, 1 + 2*is_error);
1584 
1585  id(0) = arg2;
1586  st(0) = arg1;
1587 
1588  // Since internal Octave functions are not compatible,
1589  // and "all"=="error" causes any "on" to throw an error,
1590  // turning all warnings into errors should disable
1591  // Octave:language-extension.
1592 
1593  if (is_error)
1594  {
1595  id(1) = "Octave:language-extension";
1596  st(1) = "off";
1597 
1598  id(2) = "Octave:single-quote-string";
1599  st(2) = "off";
1600  }
1601 
1602  tmp.assign ("identifier", id);
1603  tmp.assign ("state", st);
1604 
1605  warning_options = tmp;
1606 
1607  done = true;
1608  }
1609  else if (arg2 == "backtrace")
1610  {
1611  if (arg1 != "error")
1612  {
1613  Vbacktrace_on_warning = (arg1 == "on");
1614  done = true;
1615  }
1616  }
1617  else if (arg2 == "debug")
1618  {
1619  if (arg1 != "error")
1620  {
1621  Vdebug_on_warning = (arg1 == "on");
1622  done = true;
1623  }
1624  }
1625  else if (arg2 == "verbose")
1626  {
1627  if (arg1 != "error")
1628  {
1629  Vverbose_warning = (arg1 == "on");
1630  done = true;
1631  }
1632  }
1633  else if (arg2 == "quiet")
1634  {
1635  if (arg1 != "error")
1636  {
1637  Vquiet_warning = (arg1 == "on");
1638  done = true;
1639  }
1640  }
1641  else
1642  {
1643  if (arg2 == "last")
1644  arg2 = Vlast_warning_id;
1645 
1646  set_warning_option (arg1, arg2);
1647 
1648  done = true;
1649  }
1650 
1651  if (done && nargout > 0)
1652  retval = old_warning_options;
1653  }
1654  else if (arg1 == "query")
1655  {
1656  if (arg2 == "all")
1657  retval = warning_options;
1658  else if (arg2 == "backtrace" || arg2 == "debug"
1659  || arg2 == "verbose" || arg2 == "quiet")
1660  {
1662  tmp.assign ("identifier", arg2);
1663  if (arg2 == "backtrace")
1664  tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off");
1665  else if (arg2 == "debug")
1666  tmp.assign ("state", Vdebug_on_warning ? "on" : "off");
1667  else if (arg2 == "verbose")
1668  tmp.assign ("state", Vverbose_warning ? "on" : "off");
1669  else
1670  tmp.assign ("state", Vquiet_warning ? "on" : "off");
1671 
1672  retval = tmp;
1673  }
1674  else
1675  retval = warning_query (arg2);
1676 
1677  done = true;
1678  }
1679  }
1680  else if (nargin == 0)
1681  {
1682  if (nargout > 0)
1683  retval = warning_options;
1684  else
1685  display_warning_options (octave_stdout);
1686 
1687  done = true;
1688  }
1689  else if (nargin == 1)
1690  {
1691  octave_value arg = args(0);
1692 
1693  octave_map old_warning_options = warning_options;
1694 
1695  if (arg.is_map ())
1696  {
1697  octave_map m = arg.map_value ();
1698 
1699  if (! m.contains ("identifier") || ! m.contains ("state"))
1700  error ("warning: STATE structure must have fields 'identifier' and 'state'");
1701 
1702  // Simply step through the struct elements one at a time.
1703 
1704  Cell ident = m.contents ("identifier");
1705  Cell state = m.contents ("state");
1706 
1707  octave_idx_type nel = ident.numel ();
1708 
1709  for (octave_idx_type i = 0; i < nel; i++)
1710  {
1711  std::string tst = state(i).string_value ();
1712  std::string tid = ident(i).string_value ();
1713 
1714  set_warning_option (tst, tid);
1715  }
1716 
1717  done = true;
1718 
1719  if (nargout > 0)
1720  retval = old_warning_options;
1721  }
1722  }
1723 
1724  if (! done)
1725  {
1726  octave_value_list nargs = args;
1727 
1728  std::string id;
1729 
1730  bool have_fmt = maybe_extract_message_id ("warning", args, nargs, id);
1731 
1733 
1734  std::string curr_msg = handle_message (warning_with_id, id.c_str (),
1735  "unspecified warning", nargs,
1736  have_fmt);
1737 
1738  if (nargout > 0)
1739  retval = prev_msg;
1740  }
1741 
1742  return retval;
1743 }
1744 
1745 /*
1746 %!test <45753>
1747 %! warning ("error");
1748 %! assert (! isempty (help ("warning")));
1749 */
1750 
1752 set_warning_state (const std::string& id, const std::string& state)
1753 {
1755 
1756  args(1) = id;
1757  args(0) = state;
1758 
1759  return Fwarning (args, 1);
1760 }
1761 
1764 {
1765  return Fwarning (args, 1);
1766 }
1767 
1768 void
1769 disable_warning (const std::string& id)
1770 {
1771  set_warning_option ("off", id);
1772 }
1773 
1774 void
1776 {
1778 
1779  // Most people will want to have the following disabled.
1780 
1781  disable_warning ("Octave:array-as-logical");
1782  disable_warning ("Octave:array-to-scalar");
1783  disable_warning ("Octave:array-to-vector");
1784  disable_warning ("Octave:imag-to-real");
1785  disable_warning ("Octave:language-extension");
1786  disable_warning ("Octave:missing-semicolon");
1787  disable_warning ("Octave:neg-dim-as-zero");
1788  disable_warning ("Octave:resize-on-range-error");
1789  disable_warning ("Octave:separator-insert");
1790  disable_warning ("Octave:single-quote-string");
1791  disable_warning ("Octave:str-to-num");
1792  disable_warning ("Octave:mixed-string-concat");
1793  disable_warning ("Octave:variable-switch-label");
1794 }
1795 
1796 DEFUN (lasterror, args, ,
1797  doc: /* -*- texinfo -*-
1798 @deftypefn {} {@var{lasterr} =} lasterror ()
1799 @deftypefnx {} {} lasterror (@var{err})
1800 @deftypefnx {} {} lasterror ("reset")
1801 Query or set the last error message structure.
1802 
1803 When called without arguments, return a structure containing the last error
1804 message and other information related to this error. The elements of the
1805 structure are:
1806 
1807 @table @code
1808 @item message
1809 The text of the last error message
1810 
1811 @item identifier
1812 The message identifier of this error message
1813 
1814 @item stack
1815 A structure containing information on where the message occurred. This may
1816 be an empty structure if the information cannot be obtained. The fields of
1817 the structure are:
1818 
1819 @table @code
1820 @item file
1821 The name of the file where the error occurred
1822 
1823 @item name
1824 The name of function in which the error occurred
1825 
1826 @item line
1827 The line number at which the error occurred
1828 
1829 @item column
1830 An optional field with the column number at which the error occurred
1831 @end table
1832 @end table
1833 
1834 The last error structure may be set by passing a scalar structure,
1835 @var{err}, as input. Any fields of @var{err} that match those above are
1836 set while any unspecified fields are initialized with default values.
1837 
1838 If @code{lasterror} is called with the argument @qcode{"reset"}, all
1839 fields are set to their default values.
1840 @seealso{lasterr, error, lastwarn}
1841 @end deftypefn */)
1842 {
1843  int nargin = args.length ();
1844 
1845  if (nargin > 1)
1846  print_usage ();
1847 
1849 
1850  err.assign ("message", Vlast_error_message);
1851  err.assign ("identifier", Vlast_error_id);
1852 
1853  err.assign ("stack", octave_value (Vlast_error_stack));
1854 
1855  if (nargin == 1)
1856  {
1857  if (args(0).is_string ())
1858  {
1859  if (args(0).string_value () != "reset")
1860  error ("lasterror: unrecognized string argument");
1861 
1862  Vlast_error_message = "";
1863  Vlast_error_id = "";
1864 
1865  Vlast_error_stack = initialize_last_error_stack ();
1866  }
1867  else if (args(0).is_map ())
1868  {
1869  octave_scalar_map new_err = args(0).scalar_map_value ();
1870  octave_scalar_map new_err_stack;
1871  std::string new_error_message;
1872  std::string new_error_id;
1873  std::string new_error_file;
1874  std::string new_error_name;
1875  int new_error_line = -1;
1876  int new_error_column = -1;
1877  bool initialize_stack = false;
1878 
1879  if (new_err.contains ("message"))
1880  {
1881  const std::string tmp =
1882  new_err.getfield ("message").string_value ();
1883  new_error_message = tmp;
1884  }
1885 
1886  if (new_err.contains ("identifier"))
1887  {
1888  const std::string tmp =
1889  new_err.getfield ("identifier").string_value ();
1890  new_error_id = tmp;
1891  }
1892 
1893  if (new_err.contains ("stack"))
1894  {
1895  if (new_err.getfield ("stack").is_empty ())
1896  initialize_stack = true;
1897  else
1898  {
1899  new_err_stack =
1900  new_err.getfield ("stack").scalar_map_value ();
1901 
1902  if (new_err_stack.contains ("file"))
1903  {
1904  const std::string tmp =
1905  new_err_stack.getfield ("file").string_value ();
1906  new_error_file = tmp;
1907  }
1908 
1909  if (new_err_stack.contains ("name"))
1910  {
1911  const std::string tmp =
1912  new_err_stack.getfield ("name").string_value ();
1913  new_error_name = tmp;
1914  }
1915 
1916  if (new_err_stack.contains ("line"))
1917  {
1918  const int tmp =
1919  new_err_stack.getfield ("line").nint_value ();
1920  new_error_line = tmp;
1921  }
1922 
1923  if (new_err_stack.contains ("column"))
1924  {
1925  const int tmp =
1926  new_err_stack.getfield ("column").nint_value ();
1927  new_error_column = tmp;
1928  }
1929  }
1930  }
1931 
1932  Vlast_error_message = new_error_message;
1933  Vlast_error_id = new_error_id;
1934 
1935  if (initialize_stack)
1936  Vlast_error_stack = initialize_last_error_stack ();
1937  else if (new_err.contains ("stack"))
1938  {
1939  new_err_stack.setfield ("file", new_error_file);
1940  new_err_stack.setfield ("name", new_error_name);
1941  new_err_stack.setfield ("line", new_error_line);
1942  new_err_stack.setfield ("column", new_error_column);
1943  Vlast_error_stack = new_err_stack;
1944  }
1945  else
1946  {
1947  // No stack field. Fill it in with backtrace info.
1948  octave_idx_type curr_frame = -1;
1949 
1950  Vlast_error_stack
1951  = octave_call_stack::backtrace (0, curr_frame);
1952  }
1953  }
1954  else
1955  error ("lasterror: argument must be a structure or a string");
1956  }
1957 
1958  return ovl (err);
1959 }
1960 
1961 /*
1962 ## Test lasterror with empty error state
1963 %!test
1964 %! lasterror ("reset");
1965 %! x = lasterror ();
1966 %! assert (x.identifier, "")
1967 %! assert (x.message, "")
1968 %! assert (isempty (x.stack))
1969 %! lasterror (x);
1970 %! y = lasterror ();
1971 %! assert (y, x);
1972 */
1973 
1974 DEFUN (lasterr, args, nargout,
1975  doc: /* -*- texinfo -*-
1976 @deftypefn {} {[@var{msg}, @var{msgid}] =} lasterr ()
1977 @deftypefnx {} {} lasterr (@var{msg})
1978 @deftypefnx {} {} lasterr (@var{msg}, @var{msgid})
1979 Query or set the last error message.
1980 
1981 When called without input arguments, return the last error message and
1982 message identifier.
1983 
1984 With one argument, set the last error message to @var{msg}.
1985 
1986 With two arguments, also set the last message identifier.
1987 @seealso{lasterror, error, lastwarn}
1988 @end deftypefn */)
1989 {
1990  int nargin = args.length ();
1991 
1992  if (nargin > 2)
1993  print_usage ();
1994 
1995  string_vector argv = args.make_argv ("lasterr");
1996 
1997  std::string prev_error_id = Vlast_error_id;
1998  std::string prev_error_message = Vlast_error_message;
1999 
2000  if (nargin == 2)
2001  {
2002  Vlast_error_id = argv[2];
2003  Vlast_error_message = argv[1];
2004  }
2005  else if (nargin == 1)
2006  {
2007  Vlast_error_id = "";
2008  Vlast_error_message = argv[1];
2009  }
2010 
2011  if (nargin == 0 || nargout > 0)
2012  return ovl (prev_error_message, prev_error_id);
2013  else
2014  return ovl ();
2015 }
2016 
2017 DEFUN (lastwarn, args, nargout,
2018  doc: /* -*- texinfo -*-
2019 @deftypefn {} {[@var{msg}, @var{msgid}] =} lastwarn ()
2020 @deftypefnx {} {} lastwarn (@var{msg})
2021 @deftypefnx {} {} lastwarn (@var{msg}, @var{msgid})
2022 Query or set the last warning message.
2023 
2024 When called without input arguments, return the last warning message and
2025 message identifier.
2026 
2027 With one argument, set the last warning message to @var{msg}.
2028 
2029 With two arguments, also set the last message identifier.
2030 @seealso{warning, lasterror, lasterr}
2031 @end deftypefn */)
2032 {
2033  int nargin = args.length ();
2034 
2035  if (nargin > 2)
2036  print_usage ();
2037 
2038  string_vector argv = args.make_argv ("lastwarn");
2039 
2040  std::string prev_warning_id = Vlast_warning_id;
2041  std::string prev_warning_message = Vlast_warning_message;
2042 
2043  if (nargin == 2)
2044  {
2045  Vlast_warning_id = argv[2];
2046  Vlast_warning_message = argv[1];
2047  }
2048  else if (nargin == 1)
2049  {
2050  Vlast_warning_id = "";
2051  Vlast_warning_message = argv[1];
2052  }
2053 
2054  if (nargin == 0 || nargout > 0)
2055  return ovl (prev_warning_message, prev_warning_id);
2056  else
2057  return ovl ();
2058 }
2059 
2060 // FIXME: Deprecated in 4.0 and scheduled for removal in 4.4.
2061 
2062 DEFUN (__usage__, args, ,
2063  doc: /* -*- texinfo -*-
2064 @deftypefn {} {} usage (@var{msg})
2065 Print the message @var{msg}, prefixed by the string @samp{usage: }, and
2066 set Octave's internal error state such that control will return to the
2067 top level without evaluating any more commands. This is useful for
2068 aborting from functions.
2069 
2070 After @code{usage} is evaluated, Octave will print a traceback of all
2071 the function calls leading to the usage message.
2072 
2073 You should use this function for reporting problems errors that result
2074 from an improper call to a function, such as calling a function with an
2075 incorrect number of arguments, or with arguments of the wrong type. For
2076 example, most functions distributed with Octave begin with code like
2077 this
2078 
2079 @example
2080 @group
2081 if (nargin != 2)
2082  usage ("foo (a, b)");
2083 endif
2084 @end group
2085 @end example
2086 
2087 @noindent
2088 to check for the proper number of arguments.
2089 @end deftypefn */)
2090 {
2091  handle_message (usage_with_id, "", "unknown", args, true);
2092  return ovl ();
2093 }
2094 
2095 DEFUN (beep_on_error, args, nargout,
2096  doc: /* -*- texinfo -*-
2097 @deftypefn {} {@var{val} =} beep_on_error ()
2098 @deftypefnx {} {@var{old_val} =} beep_on_error (@var{new_val})
2099 @deftypefnx {} {} beep_on_error (@var{new_val}, "local")
2100 Query or set the internal variable that controls whether Octave will try
2101 to ring the terminal bell before printing an error message.
2102 
2103 When called from inside a function with the @qcode{"local"} option, the
2104 variable is changed locally for the function and any subroutines it calls.
2105 The original variable value is restored when exiting the function.
2106 @end deftypefn */)
2107 {
2108  return SET_INTERNAL_VARIABLE (beep_on_error);
2109 }
2110 
2111 DEFUN (debug_on_error, args, nargout,
2112  doc: /* -*- texinfo -*-
2113 @deftypefn {} {@var{val} =} debug_on_error ()
2114 @deftypefnx {} {@var{old_val} =} debug_on_error (@var{new_val})
2115 @deftypefnx {} {} debug_on_error (@var{new_val}, "local")
2116 Query or set the internal variable that controls whether Octave will try
2117 to enter the debugger when an error is encountered.
2118 
2119 This will also inhibit printing of the normal traceback message (you will
2120 only see the top-level error message).
2121 
2122 When called from inside a function with the @qcode{"local"} option, the
2123 variable is changed locally for the function and any subroutines it calls.
2124 The original variable value is restored when exiting the function.
2125 @seealso{debug_on_warning, debug_on_interrupt}
2126 @end deftypefn */)
2127 {
2128  return SET_INTERNAL_VARIABLE (debug_on_error);
2129 }
2130 
2131 DEFUN (debug_on_warning, args, nargout,
2132  doc: /* -*- texinfo -*-
2133 @deftypefn {} {@var{val} =} debug_on_warning ()
2134 @deftypefnx {} {@var{old_val} =} debug_on_warning (@var{new_val})
2135 @deftypefnx {} {} debug_on_warning (@var{new_val}, "local")
2136 Query or set the internal variable that controls whether Octave will try
2137 to enter the debugger when a warning is encountered.
2138 
2139 When called from inside a function with the @qcode{"local"} option, the
2140 variable is changed locally for the function and any subroutines it calls.
2141 The original variable value is restored when exiting the function.
2142 @seealso{debug_on_error, debug_on_interrupt}
2143 @end deftypefn */)
2144 {
2145  return SET_INTERNAL_VARIABLE (debug_on_warning);
2146 }
2147 
2149 last_error_message (void)
2150 {
2151  return Vlast_error_message;
2152 }
2153 
2155 last_error_id (void)
2156 {
2157  return Vlast_error_id;
2158 }
2159 
2160 octave_map
2161 last_error_stack (void)
2162 {
2163  return Vlast_error_stack;
2164 }
2165 
2167 last_warning_message (void)
2168 {
2169  return Vlast_warning_message;
2170 }
2171 
2173 last_warning_id (void)
2174 {
2175  return Vlast_warning_id;
2176 }
2177 
2178 void
2180 {
2181  frame.protect_var (buffer_error_messages);
2182  frame.protect_var (Vdebug_on_error);
2183  frame.protect_var (Vdebug_on_warning);
2184 
2185  buffer_error_messages++;
2186  Vdebug_on_error = false;
2187  Vdebug_on_warning = false;
2188  // leave Vdebug_on_caught as it was, so errors in try/catch are still caught
2189 }
uint32_t id
Definition: graphics.cc:11587
bool Vdebug_on_error
Definition: error.cc:61
static bool debug_on_caught(const std::string &ID)
Definition: debug.h:133
int warning_enabled(const std::string &id)
Definition: error.cc:661
void panic(const char *fmt,...)
Definition: error.cc:931
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:803
void flush_octave_stdout(void)
Definition: pager.cc:454
const Cell & contents(const_iterator p) const
Definition: oct-map.h:313
scalar structure containing the fields
Definition: ov-struct.cc:1688
Definition: Cell.h:37
OCTAVE_EXPORT octave_value_list column
Definition: sparse.cc:123
octave_idx_type nfields(void) const
Definition: oct-map.h:203
bool Vdebug_on_caught
Definition: error.cc:65
std::string fcn_name(bool print_subfn=true) const
Definition: call-stack.cc:45
bool Vdebug_on_warning
Definition: error.cc:69
octave_map xmap_value(const char *fmt,...) const
Definition: ov.cc:2130
static bool at_top_level(void)
Definition: symtab.h:1300
static bool Vbeep_on_error
Definition: error.cc:56
void vparse_error(const char *fmt, va_list args)
Definition: error.cc:812
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:347
OCTINTERP_API void initialize_default_warning_state(void)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
OCTINTERP_API size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
void verror_with_id(const char *id, const char *fmt, va_list args)
Definition: error.cc:609
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
void rethrow_error(const char *id, const char *fmt,...)
Definition: error.cc:842
std::string doc
Definition: ov-fcn.h:217
octave_idx_type length(void) const
Definition: ovl.h:96
const octave_value & contents(const_iterator p) const
Definition: oct-map.h:190
octave_map map_value(void) const
Definition: ov.cc:1693
bool contains(const std::string &name) const
Definition: oct-map.h:332
bool is_defined(void) const
Definition: ov.h:536
static void vwarning(const char *name, const char *id, const char *fmt, va_list args)
Definition: error.cc:389
bool contains(const std::string &name) const
Definition: oct-map.h:209
void vmessage(const char *name, const char *fmt, va_list args)
Definition: error.cc:424
static OCTAVE_NORETURN void error_1(octave::execution_exception &e, std::ostream &os, const char *name, const char *id, const char *fmt, va_list args, bool with_cfn=false)
Definition: error.cc:507
void protect_var(T &var)
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
std::string name(void) const
Definition: ov-fcn.h:163
#define SET_INTERNAL_VARIABLE(NM)
Definition: variables.h:126
OCTINTERP_API octave_value_list set_warning_state(const std::string &id, const std::string &state)
static octave_function * current(void)
Definition: call-stack.h:108
void setfield(const std::string &key, const octave_value &val)
Definition: oct-map.cc:178
static octave_map initialize_last_error_stack(void)
Definition: error.cc:143
static std::string Vlast_error_message
Definition: error.cc:85
void message_with_id(const char *name, const char *id, const char *fmt,...)
Definition: error.cc:446
octave_idx_type numel(void) const
Definition: oct-map.h:371
#define octave_diary
Definition: pager.h:148
static bool Vverbose_warning
Definition: error.cc:76
static OCTAVE_NORETURN void usage_1(octave::execution_exception &e, const char *id, const char *fmt, va_list args)
Definition: error.cc:456
static bool debug_on_warn(const std::string &ID)
Definition: debug.h:140
i e
Definition: data.cc:2724
static std::string Vlast_warning_id
Definition: error.cc:91
void usage(const char *fmt,...)
Definition: error.cc:482
void usage_with_id(const char *id, const char *fmt,...)
Definition: error.cc:497
bool is_empty(void) const
Definition: ov-base.h:355
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
Definition: symtab.h:1373
static octave::execution_exception make_execution_exception(const char *who)
Definition: error.cc:339
octave_value arg
Definition: pr-output.cc:3440
octave_function * fcn
Definition: ov-class.cc:1743
string_vector argv
Definition: load-save.cc:635
virtual symbol_table::scope_id scope(void)
Definition: ov-fcn.h:77
virtual bool is_map(void) const
Definition: ov-base.h:385
OCTAVE_EXPORT octave_value_list search each directory of the loadpath for element of the cell array and return the first that matches If the second optional argument return a cell array containing the list of all files that have the same name in the path If no files are found
Definition: utils.cc:302
static std::string Vlast_warning_message
Definition: error.cc:88
JNIEnv void * args
Definition: ov-java.cc:67
static bool Vquiet_warning
Definition: error.cc:79
static std::string handle_message(error_fun f, const char *id, const char *msg, const octave_value_list &args, bool have_fmt)
Definition: error.cc:962
static void maybe_enter_debugger(octave::execution_exception &e, bool show_stack_trace=false)
Definition: error.cc:353
static bool Vbacktrace_on_warning
Definition: error.cc:73
void message(const char *name, const char *fmt,...)
Definition: error.cc:430
void verror_with_cfn(const char *fmt, va_list args)
Definition: error.cc:594
done
Definition: syscalls.cc:248
static void pr_where(std::ostream &os, const char *who, const std::list< error_stack_frame > &frames)
Definition: error.cc:280
int buffer_error_messages
Definition: error.cc:111
static octave_user_code * caller_user_code(size_t nskip=0)
Definition: call-stack.h:172
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
Definition: error.cc:624
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTINTERP_API void disable_warning(const std::string &id)
void clear(void)
Definition: oct-map.h:364
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
static symbol_table::scope_id current_scope(void)
Definition: call-stack.h:147
static size_t current_frame(void)
Definition: call-stack.h:131
OCTINTERP_API std::string last_warning_id(void)
string_vector make_argv(const std::string &="") const
Definition: ovl.cc:214
void defun_usage_message(const std::string &msg)
Definition: error.cc:952
static octave_map Vlast_error_stack
Definition: error.cc:97
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
std::string string_value(bool force=false) const
Definition: ov.h:908
void error_with_cfn(const char *fmt,...)
Definition: error.cc:600
virtual std::string string_value(bool force=false) const
Definition: ov-base.cc:838
void error_with_id(const char *id, const char *fmt,...)
Definition: error.cc:615
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
static size_t current_frame
Definition: pt-eval.h:158
int nint_value(bool frc_str_conv=false) const
Definition: ov.h:753
void vusage_with_id(const char *id, const char *fmt, va_list args)
Definition: error.cc:491
int nargin
Definition: graphics.cc:10115
bool is_string(void) const
Definition: ov.h:578
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
Definition: oct-string.cc:112
void vparse_error_with_id(const char *id, const char *fmt, va_list args)
Definition: error.cc:827
int in_try_catch
Definition: error.cc:115
OCTINTERP_API std::string last_error_id(void)
int error_state
Definition: error.cc:106
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
double tmp
Definition: data.cc:6300
std::string name
Definition: error.cc:274
static void rethrow_error_1(const char *id, const char *fmt,...)
Definition: error.cc:882
void vmessage_with_id(const char *name, const char *id, const char *fmt, va_list args)
Definition: error.cc:439
octave_value retval
Definition: data.cc:6294
#define panic_impossible()
Definition: error.h:40
void reset_error_handler(void)
Definition: error.cc:124
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
Definition: symtab.h:1330
static void warning_1(const char *id, const char *fmt, va_list args)
Definition: error.cc:732
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
static bool debug_mode
Definition: pt-eval.h:160
T::size_type strlen(const typename T::value_type *str)
Definition: oct-string.cc:75
void parse_error(const char *fmt,...)
Definition: error.cc:818
void vusage(const char *fmt, va_list args)
Definition: error.cc:476
static uint32_t state[624]
Definition: randmtzig.cc:184
bool is_map(void) const
Definition: ov.h:590
void warning(const char *fmt,...)
Definition: error.cc:788
octave::unwind_protect frame
Definition: graphics.cc:11584
OCTINTERP_API std::string last_error_message(void)
bool is_empty(void) const
Definition: ov.h:542
OCTINTERP_API octave_map last_error_stack(void)
static void defun_usage_message_1(const char *fmt,...)
Definition: error.cc:943
#define octave_stdout
Definition: pager.h:146
OCTINTERP_API octave_value_list Fwarning(const octave_value_list &=octave_value_list(), int=0)
bool all_strings_p(void) const
Definition: ovl.cc:163
static std::string Vlast_error_id
Definition: error.cc:94
octave_value do_keyboard(const octave_value_list &args=octave_value_list())
octave_scalar_map scalar_map_value(void) const
Definition: ov.cc:1699
static octave_map warning_options
Definition: error.cc:82
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
static void verror(bool save_last_error, std::ostream &os, const char *name, const char *id, const char *fmt, va_list args, bool with_cfn=false)
Definition: error.cc:149
virtual bool is_string(void) const
Definition: ov-base.h:379
p
Definition: lu.cc:138
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:223
static symbol_table::context_id current_context(void)
Definition: call-stack.h:152
void error_with_id_cfn(const char *id, const char *fmt,...)
Definition: error.cc:630
void(* error_fun)(const char *, const char *,...)
Definition: error.cc:957
static void initialize_warning_options(const std::string &state)
Definition: error.cc:132
static std::list< octave_call_stack::stack_frame > backtrace_frames(size_t nskip=0)
Definition: call-stack.h:294
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
octave_idx_type length(void) const
Definition: oct-map.h:372
void parse_error_with_id(const char *id, const char *fmt,...)
Definition: error.cc:833
bool is_empty(void) const
Definition: oct-map.h:373
octave_value getfield(const std::string &key) const
Definition: oct-map.cc:171
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
Definition: error.cc:1036
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:547
static octave_map empty_backtrace(void)
Definition: call-stack.cc:362
OCTINTERP_API std::string last_warning_message(void)
void vwarning_with_id(const char *id, const char *fmt, va_list args)
Definition: error.cc:797
bool discard_warning_messages
Definition: error.cc:121
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
bool discard_error_messages
Definition: error.cc:118
static int check_state(const std::string &state)
Definition: error.cc:639
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
static bool debug_on_err(const std::string &ID)
Definition: debug.h:126
static std::list< error_stack_frame > make_stack_frame_list(const octave_map &stack)
Definition: error.cc:851
OCTINTERP_API void interpreter_try(octave::unwind_protect &)
octave_value_list Fsprintf(const octave_value_list &, int)
static octave_map backtrace(size_t nskip=0)
Definition: call-stack.h:276
static void pr_where_1(std::ostream &os, const char *fmt,...)
Definition: error.cc:263
static void pr_where_2(std::ostream &os, const char *fmt, va_list args)
Definition: error.cc:235