26#if defined (HAVE_CONFIG_H)
43#include "builtin-defun-decls.h"
62format_message (
const char *fmt, va_list args)
67 std::ostringstream output_buf;
69 octave::vformat (output_buf, fmt, args);
71 return output_buf.str ();
76error_1 (octave::execution_exception& ee,
const char *
id,
const char *fmt,
79 octave::error_system& es = octave::__get_error_system__ ();
81 es.error_1 (ee,
id, fmt, args);
86error_1 (
const char *
id,
const char *fmt, va_list args)
88 octave::error_system& es = octave::__get_error_system__ ();
90 es.error_1 (
id, fmt, args);
94check_state (
const std::string& state)
103 else if (state ==
"on")
105 else if (state ==
"error")
112vwarning (
const char *
id,
const char *fmt, va_list args)
114 octave::error_system& es = octave::__get_error_system__ ();
116 es.vwarning (
id, fmt, args);
120defun_usage_message (
const char *fmt, ...)
123 va_start (args, fmt);
124 error_1 (
"", fmt, args);
128typedef void (*
error_fcn)(
const char *,
const char *, ...);
131handle_message (
error_fcn f,
const char *
id,
const char *msg,
157 msg = tmpstr.c_str ();
169 if (msg[
len - 1] ==
'\n')
173 std::string tmp_msg (msg,
len - 1);
174 f (
id,
"%s\n", tmp_msg.c_str ());
192maybe_extract_message_id (
const std::string& caller,
200 int nargin = args.
length ();
202 bool have_fmt = nargin > 1;
206 std::string arg1 = args(0).xstring_value (
"%s: MESSAGE must be a string",
213 if (arg1.find_first_of (
"% \f\n\r\t\v") == std::string::npos
214 && arg1.find (
':') != std::string::npos
216 && arg1.back () !=
':')
224 for (
int i = 1; i < nargin; i++)
225 nargs(i-1) = args(i);
228 nargs(0) =
"call to " + caller
229 +
" with message identifier '" + arg1
230 +
"' requires message";
240init_warning_options (
const std::string& state)
244 initw.
setfield (
"identifier",
"all");
259 : m_interpreter (interp),
260 m_debug_on_error (false),
261 m_debug_on_caught (false),
262 m_debug_on_warning (false),
263 m_discard_warning_messages (false),
264 m_beep_on_error (false),
265 m_backtrace_on_warning (true),
266 m_verbose_warning (false),
267 m_quiet_warning (false),
268 m_warning_options (init_warning_options (
"on")),
269 m_last_error_message (),
270 m_last_warning_message (),
271 m_last_warning_id (),
273 m_last_error_stack (init_error_stack (interp))
304 "discard_warning_messages");
319 "backtrace_on_warning");
340 "last_error_message");
348 "last_warning_message");
367static const char *bt_fieldnames[] =
368{
"file",
"name",
"line",
"column",
nullptr };
375 std::size_t nframes = frames.size ();
386 for (
const auto& frm : frames)
388 file(k) = frm.file_name ();
389 name(k) = frm.fcn_name ();
390 line(k) = frm.line ();
391 column(k) = frm.
column ();
399static std::list<frame_info>
400make_stack_frame_list_intern (
const octave_map& stack)
402 std::list<frame_info> frames;
412 frames.push_back (frame_info (file(i).string_value (),
413 name(i).string_value (),
414 line(i).int_value (),
415 column(i).int_value ()));
422 const std::string& who)
426 error (
"%s: STACK struct must contain the fields 'file', 'name', and 'line'",
433 return make_stack_frame_list_intern (stack1);
436 return make_stack_frame_list_intern (stack);
460 bool all_found =
false;
461 bool id_found =
false;
468 if (! all_found && ovs ==
"all")
470 all_state = check_state (state(i).string_value ());
476 if (! id_found && ovs ==
id)
478 id_state = check_state (state(i).string_value ());
484 if (all_found && id_found)
498 else if (all_state == 1)
500 if (id_state == 0 || id_state == 2)
505 else if (all_state == 2)
519 std::string str_id =
id ? id :
"";
520 std::string
message = format_message (fmt, args);
527 const char *fmt, va_list args)
537 std::string base_msg = format_message (fmt, args);
538 std::string msg_string;
541 msg_string = std::string (name) +
": ";
543 msg_string += base_msg;
559 bool fmt_suppresses_backtrace =
false;
560 std::size_t fmt_len = (fmt ?
strlen (fmt) : 0);
561 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
563 if (! fmt_suppresses_backtrace)
575 std::cerr << msg_string;
577 if (! fmt_suppresses_backtrace && in_user_code
583 if (! bt_msg.empty ())
584 bt_msg =
"warning: called from\n" + bt_msg;
587 std::cerr << bt_msg << std::endl;
605 const char *fmt, va_list args)
607 ee.set_identifier (
id);
608 ee.set_message (format_message (fmt, args));
617 std::string
message = format_message (fmt, args);
619 std::list<frame_info> stack_info;
632 vwarning (
"warning",
id, fmt, args);
637 const std::string& msg,
640 std::list<frame_info> stack_info;
668 va_start (args, fmt);
678 std::string
id = id_arg;
698 if (ident(i).string_value () ==
id)
700 val = state(i).string_value ();
710 if (ident(i).string_value () ==
"all")
712 val = state(i).string_value ();
724 retval.
assign (
"identifier",
id);
725 retval.
assign (
"state", val);
733 std::string retval =
"on";
744 if (ident(i).string_value () ==
"all")
746 retval = state(i).string_value ();
766 if (all_state ==
"on")
767 os <<
"By default, warnings are enabled.";
768 else if (all_state ==
"off")
769 os <<
"By default, warnings are disabled.";
770 else if (all_state ==
"error")
771 os <<
"By default, warnings are treated as errors.";
773 error (
"unexpected default warning state '%s' - please report this bug", all_state.c_str ());
778 os <<
"Non-default warning states are:\n\n";
779 os <<
" State Warning ID\n";
786 std::string tid = ident(i).string_value ();
787 std::string tst = state(i).string_value ();
789 os << std::setw (7) << tst <<
" " << tid <<
"\n";
797 const std::string& ident)
801 if (state !=
"on" && state !=
"off" && state !=
"error")
802 error (
"invalid warning state: %s", state.c_str ());
813 if (tid(i).string_value () == ident)
819 if (state == all_state && ident !=
"all")
821 for (i = i + 1; i < nel; i++)
835 opts.
assign (
"identifier", tid);
836 opts.
assign (
"state", tst);
854 opts.
assign (
"identifier", tid);
855 opts.
assign (
"state", tst);
891 m_debug_on_error =
false;
894 m_debug_on_warning =
false;
902 const std::string&
id,
904 const std::list<frame_info>& stack_info_arg)
906 std::list<frame_info> stack_info = stack_info_arg;
908 if (stack_info.empty ())
917 stack_info.unique ();
935 std::string
message = ee.message ();
959OCTAVE_END_NAMESPACE(octave)
962vmessage (
const char *name,
const char *fmt, va_list args)
967 message = std::string (name) +
": ";
969 message += format_message (fmt, args);
972 std::cerr <<
message << std::endl;
976message (
const char *name,
const char *fmt, ...)
979 va_start (args, fmt);
987 octave::error_system& es = octave::__get_error_system__ ();
989 es.vusage (
id, fmt, args);
996 va_start (args, fmt);
1004 error_1 (
"", fmt, args);
1011 va_start (args, fmt);
1017verror (octave::execution_exception& ee,
const char *fmt, va_list args)
1019 error_1 (ee,
"", fmt, args);
1023error (octave::execution_exception& ee,
const char *fmt, ...)
1026 va_start (args, fmt);
1034 error_1 (
"", fmt, args);
1041 va_start (args, fmt);
1049 error_1 (
id, fmt, args);
1056 va_start (args, fmt);
1064 error_1 (
id, fmt, args);
1071 va_start (args, fmt);
1077vwarning (
const char *fmt, va_list args)
1079 vwarning (
"", fmt, args);
1086 va_start (args, fmt);
1087 vwarning (fmt, args);
1094 vwarning (
id, fmt, args);
1101 va_start (args, fmt);
1102 vwarning (
id, fmt, args);
1109 error_1 (
"", fmt, args);
1116 va_start (args, fmt);
1124 error_1 (
id, fmt, args);
1131 va_start (args, fmt);
1139defun_usage_message (
const std::string& msg)
1141 ::defun_usage_message (
"%s", msg.c_str ());
1162 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1167 octave_map err_stack = init_error_stack (interp);
1296 int nargin = args.
length ();
1305 std::list<frame_info> stack_info;
1307 bool have_fmt =
false;
1309 if (nargin == 1 && args(0).isstruct ())
1312 if (args(0).isempty ())
1315 octave_scalar_map m = args(0).xscalar_map_value (
"ERRSTRUCT must be a scalar structure with fields 'message' and 'identifier'");
1323 "error: ERRSTRUCT must have field 'message'");
1334 "error: ERRSTRUCT must have field 'identifier'");
1340 id = c.
xstring_value (
"error: IDENTIFIER must be a string");
1359 have_fmt = maybe_extract_message_id (
"error", args, nargs,
id);
1361 if (nargs.
length () == 0)
1362 message =
"unspecified error";
1609 int nargin = args.
length ();
1618 std::string arg1 = argv[1];
1619 std::transform (arg1.begin (), arg1.end (), arg1.begin (), tolower);
1620 std::string arg2 =
"all";
1621 std::string arg2_lc =
"all";
1627 std::transform (arg2_lc.begin (), arg2_lc.end (), arg2_lc.begin (),
1631 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1635 if (arg2_lc ==
"all")
1642 std::string arg3_lc = argv[3];
1643 std::transform (arg3_lc.begin (), arg3_lc.end (),
1644 arg3_lc.begin (), tolower);
1665 fields(0) =
"identifier";
1666 fields(1) =
"state";
1677 for (i = 0; i < nel; i++)
1679 std::string
id = ids(i).string_value ();
1683 states(i) = curr_state;
1697 states(nel) = curr_state;
1712 && (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error"))
1713 || (nargin >= 2 && arg2_lc ==
"all"))
1716 if (arg1 ==
"error")
1717 error (R
"(warning: cannot specify "all" warning ID with state "error")");
1727 tmp.
assign (
"identifier",
id);
1728 tmp.
assign (
"state", st);
1734 else if (arg2_lc ==
"backtrace")
1736 if (arg1 !=
"error")
1742 else if (arg2_lc ==
"debug")
1744 if (arg1 !=
"error")
1750 else if (arg2_lc ==
"verbose")
1752 if (arg1 !=
"error")
1758 else if (arg2_lc ==
"quiet")
1760 if (arg1 !=
"error")
1768 if (arg2_lc ==
"last")
1776 if (done && nargout > 0)
1777 retval = old_warning_options;
1779 else if (arg1 ==
"query")
1781 if (arg2_lc ==
"all")
1788 else if (arg2_lc ==
"backtrace" || arg2_lc ==
"debug"
1789 || arg2_lc ==
"verbose" || arg2_lc ==
"quiet")
1794 tmp.
assign (
"identifier", arg2_lc);
1795 if (arg2_lc ==
"backtrace")
1797 else if (arg2_lc ==
"debug")
1799 else if (arg2_lc ==
"verbose")
1808 if (arg2_lc ==
"backtrace")
1812 else if (arg2_lc ==
"debug")
1816 else if (arg2_lc ==
"verbose")
1834 octave_stdout <<
'"' << arg2 << R
"(" warning state is ")" <<
1843 else if (nargin == 0)
1852 else if (nargin == 1)
1863 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1874 Cell oldstate (state);
1878 std::string tid = ident(i).string_value ();
1881 old_warning_options.
setfield (
"state", oldstate);
1886 std::string tst = state(i).string_value ();
1887 std::string tid = ident(i).string_value ();
1895 retval = old_warning_options;
1905 bool have_fmt = maybe_extract_message_id (
"warning", args, nargs,
id);
1910 "unspecified warning", nargs,
2031 int nargin = args.
length ();
2049 if (args(0).is_string ())
2051 if (args(0).string_value () !=
"reset")
2052 error (
"lasterror: unrecognized string argument");
2059 else if (args(0).isstruct ())
2063 std::string new_error_message;
2064 std::string new_error_id;
2065 std::string new_error_file;
2066 std::string new_error_name;
2067 int new_error_line = -1;
2068 int new_error_column = -1;
2069 bool initialize_stack =
false;
2073 const std::string tmp
2075 new_error_message = tmp;
2078 if (new_err.
contains (
"identifier"))
2080 const std::string tmp
2088 initialize_stack =
true;
2094 if (new_err_stack.
contains (
"file"))
2096 const std::string tmp
2098 new_error_file = tmp;
2101 if (new_err_stack.
contains (
"name"))
2103 const std::string tmp
2105 new_error_name = tmp;
2108 if (new_err_stack.
contains (
"line"))
2112 new_error_line = tmp;
2115 if (new_err_stack.
contains (
"column"))
2119 new_error_column = tmp;
2127 if (initialize_stack)
2129 else if (new_err.
contains (
"stack"))
2131 new_err_stack.
setfield (
"file", new_error_file);
2132 new_err_stack.
setfield (
"name", new_error_name);
2133 new_err_stack.
setfield (
"line", new_error_line);
2134 new_err_stack.
setfield (
"column", new_error_column);
2142 error (
"lasterror: argument must be a structure or a string");
2161DEFMETHOD (lasterr, interp, args, nargout,
2177 int nargin = args.
length ();
2194 else if (nargin == 1)
2200 if (nargin == 0 || nargout > 0)
2201 return ovl (prev_error_message, prev_error_id);
2206DEFMETHOD (lastwarn, interp, args, nargout,
2222 int nargin = args.
length ();
2239 else if (nargin == 1)
2245 if (nargin == 0 || nargout > 0)
2246 return ovl (prev_warning_message, prev_warning_id);
2251DEFMETHOD (beep_on_error, interp, args, nargout,
2269DEFMETHOD (debug_on_error, interp, args, nargout,
2291DEFMETHOD (debug_on_warning, interp, args, nargout,
2318OCTAVE_END_NAMESPACE(octave)
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
Cell column(octave_idx_type i) const
static bool forced_interactive()
bool debug_on_warn(const std::string &id)
Vector representing the dimensions (size) of an Array.
error_system(interpreter &interp)
octave_value beep_on_error(const octave_value_list &args, int nargout)
std::string last_error_message() const
void interpreter_try(unwind_protect &frame)
void display_warning_options(std::ostream &os)
static std::list< frame_info > make_stack_frame_list(const octave_map &stack, const std::string &who="error")
std::string last_warning_id() const
octave_value last_error_id(const octave_value_list &args, int nargout)
bool debug_on_error() const
OCTAVE_NORETURN void error_1(execution_exception &ee, const char *id, const char *fmt, va_list args)
OCTAVE_NORETURN void vpanic(const char *fmt, va_list args)
bool debug_on_warning() const
octave_value quiet_warning(const octave_value_list &args, int nargout)
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)
void set_warning_option(const std::string &state, const std::string &id)
bool beep_on_error() const
OCTAVE_NORETURN void rethrow_error(const std::string &id, const std::string &msg, const octave_map &stack)
bool verbose_warning() const
octave_scalar_map warning_query(const std::string &id_arg)
octave_value backtrace_on_warning(const octave_value_list &args, int nargout)
octave_value last_warning_message(const octave_value_list &args, int nargout)
OCTAVE_NORETURN void throw_error(const std::string &err_type, const std::string &id, const std::string &message, const std::list< frame_info > &stack_info=std::list< frame_info >())
octave_map last_error_stack() const
int warning_enabled(const std::string &id)
For given warning ID, return 0 if warnings are disabled, 1 if enabled, and 2 if the given ID should b...
std::string last_warning_message() const
static octave_map make_stack_map(const std::list< frame_info > &frames)
OCTAVE_NORETURN void vusage(const char *id, const char *fmt, va_list args)
octave_value debug_on_warning(const octave_value_list &args, int nargout)
octave_value verbose_warning(const octave_value_list &args, int nargout)
bool discard_warning_messages() const
octave_map warning_options() const
void disable_warning(const std::string &id)
void initialize_default_warning_state()
void vwarning(const char *name, const char *id, const char *fmt, va_list args)
octave_value last_warning_id(const octave_value_list &args, int nargout)
bool debug_on_caught() const
std::string last_error_id() const
void save_exception(const execution_exception &ee)
octave_value debug_on_error(const octave_value_list &args, int nargout)
bool quiet_warning() const
octave_value last_error_message(const octave_value_list &args, int nargout)
bool backtrace_on_warning() const
std::string default_warning_state()
void display_exception(const execution_exception &ee) const
OCTAVE_NORETURN void panic(const char *fmt,...)
Provides threadsafe access to octave.
bool display_exception(const execution_exception &ee, bool beep=false)
error_system & get_error_system()
bool at_top_level() const
tree_evaluator & get_evaluator()
event_manager & get_event_manager()
void resize(const dim_vector &dv, bool fill=false)
const Cell & contents(const_iterator p) const
void setfield(const std::string &key, const Cell &val)
octave_idx_type numel() const
bool contains(const std::string &name) const
void assign(const std::string &k, const Cell &val)
const octave_value & contents(const_iterator p) const
bool contains(const std::string &name) const
void setfield(const std::string &key, const octave_value &val)
void assign(const std::string &k, const octave_value &val)
octave_idx_type nfields() const
octave_value getfield(const std::string &key) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
bool all_strings_p() const
string_vector make_argv(const std::string &="") const
octave_idx_type length() const
octave_map xmap_value(const char *fmt,...) const
octave_scalar_map scalar_map_value() const
octave_map map_value() const
std::string string_value(bool force=false) const
int nint_value(bool frc_str_conv=false) const
std::string xstring_value(const char *fmt,...) const
octave_map empty_backtrace() const
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
bool in_user_code() const
octave_map backtrace(octave_idx_type &curr_user_frame, bool print_subfn=true) const
bp_table & get_bp_table()
std::string backtrace_message() const
std::list< frame_info > backtrace_info(octave_idx_type &curr_user_frame, bool print_subfn=true) const
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val=octave_value())
void enter_debugger(const std::string &prompt="debug> ")
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void interpreter_try(unwind_protect &frame)
void error_with_id(const char *id, const char *fmt,...)
void(* error_fcn)(const char *, const char *,...)
void usage_with_id(const char *id, const char *fmt,...)
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
void parse_error_with_id(const char *id, const char *fmt,...)
octave_value_list Fwarning(octave::interpreter &interp, const octave_value_list &args, int nargout)
void error_with_id_cfn(const char *id, const char *fmt,...)
void vwarning_with_id(const char *id, const char *fmt, va_list args)
void verror(const char *fmt, va_list args)
void verror_with_id(const char *id, const char *fmt, va_list args)
void vusage_with_id(const char *id, const char *fmt, va_list args)
void verror_with_cfn(const char *fmt, va_list args)
void error_with_cfn(const char *fmt,...)
void vparse_error_with_id(const char *id, const char *fmt, va_list args)
void parse_error(const char *fmt,...)
void error(const char *fmt,...)
void vparse_error(const char *fmt, va_list args)
void message(const char *name, const char *fmt,...)
octave_value_list set_warning_state(const std::string &id, const std::string &state)
void vmessage(const char *name, const char *fmt, va_list args)
void disable_warning(const std::string &id)
int warning_enabled(const std::string &id)
OCTAVE_NORETURN void error(const char *fmt,...)
void message(const char *name, const char *fmt,...)
octave_value_list Fsprintf(const octave_value_list &args, int)
error_system & __get_error_system__()
interpreter & __get_interpreter__()
T::size_type strlen(const typename T::value_type *str)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
#define panic_unless(cond)
F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)