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).string_value ();
212 if (arg1.find_first_of (
"% \f\n\r\t\v") == std::string::npos
213 && arg1.find (
':') != std::string::npos
215 && arg1.back () !=
':')
223 for (
int i = 1; i < nargin; i++)
224 nargs(i-1) = args(i);
227 nargs(0) =
"call to " + caller
228 +
" with message identifier '" + arg1
229 +
"' requires message";
239init_warning_options (
const std::string& state)
243 initw.
setfield (
"identifier",
"all");
258 : m_interpreter (interp),
259 m_debug_on_error (false),
260 m_debug_on_caught (false),
261 m_debug_on_warning (false),
262 m_discard_warning_messages (false),
263 m_beep_on_error (false),
264 m_backtrace_on_warning (true),
265 m_verbose_warning (false),
266 m_quiet_warning (false),
267 m_warning_options (init_warning_options (
"on")),
268 m_last_error_message (),
269 m_last_warning_message (),
270 m_last_warning_id (),
272 m_last_error_stack (init_error_stack (interp))
303 "discard_warning_messages");
318 "backtrace_on_warning");
339 "last_error_message");
347 "last_warning_message");
366static const char *bt_fieldnames[] =
367{
"file",
"name",
"line",
"column",
nullptr };
374 std::size_t nframes = frames.size ();
385 for (
const auto& frm : frames)
387 file(k) = frm.file_name ();
388 name(k) = frm.fcn_name ();
389 line(k) = frm.line ();
390 column(k) = frm.
column ();
401 std::list<frame_info> frames;
411 frames.push_back (frame_info (file(i).string_value (),
412 name(i).string_value (),
413 line(i).int_value (),
414 column(i).int_value ()));
440 bool all_found =
false;
441 bool id_found =
false;
448 if (! all_found && ovs ==
"all")
450 all_state = check_state (state(i).string_value ());
456 if (! id_found && ovs ==
id)
458 id_state = check_state (state(i).string_value ());
464 if (all_found && id_found)
478 else if (all_state == 1)
480 if (id_state == 0 || id_state == 2)
485 else if (all_state == 2)
499 std::string str_id =
id ? id :
"";
500 std::string
message = format_message (fmt, args);
507 const char *fmt, va_list args)
517 std::string base_msg = format_message (fmt, args);
518 std::string msg_string;
521 msg_string = std::string (name) +
": ";
523 msg_string += base_msg;
539 bool fmt_suppresses_backtrace =
false;
540 std::size_t fmt_len = (fmt ?
strlen (fmt) : 0);
541 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
543 if (! fmt_suppresses_backtrace)
555 std::cerr << msg_string;
557 if (! fmt_suppresses_backtrace && in_user_code
563 if (! bt_msg.empty ())
564 bt_msg =
"warning: called from\n" + bt_msg;
567 std::cerr << bt_msg << std::endl;
585 const char *fmt, va_list args)
587 ee.set_identifier (
id);
588 ee.set_message (format_message (fmt, args));
597 std::string
message = format_message (fmt, args);
599 std::list<frame_info> stack_info;
612 vwarning (
"warning",
id, fmt, args);
617 const std::string& msg,
620 std::list<frame_info> stack_info;
628 error (
"rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
663 va_start (args, fmt);
673 std::string
id = id_arg;
693 if (ident(i).string_value () ==
id)
695 val = state(i).string_value ();
705 if (ident(i).string_value () ==
"all")
707 val = state(i).string_value ();
719 retval.
assign (
"identifier",
id);
720 retval.
assign (
"state", val);
728 std::string retval =
"on";
739 if (ident(i).string_value () ==
"all")
741 retval = state(i).string_value ();
761 if (all_state ==
"on")
762 os <<
"By default, warnings are enabled.";
763 else if (all_state ==
"off")
764 os <<
"By default, warnings are disabled.";
765 else if (all_state ==
"error")
766 os <<
"By default, warnings are treated as errors.";
768 error (
"unexpected default warning state '%s' - please report this bug", all_state.c_str ());
773 os <<
"Non-default warning states are:\n\n";
774 os <<
" State Warning ID\n";
781 std::string tid = ident(i).string_value ();
782 std::string tst = state(i).string_value ();
784 os << std::setw (7) << tst <<
" " << tid <<
"\n";
792 const std::string& ident)
796 if (state !=
"on" && state !=
"off" && state !=
"error")
797 error (
"invalid warning state: %s", state.c_str ());
808 if (tid(i).string_value () == ident)
814 if (state == all_state && ident !=
"all")
816 for (i = i + 1; i < nel; i++)
830 opts.
assign (
"identifier", tid);
831 opts.
assign (
"state", tst);
849 opts.
assign (
"identifier", tid);
850 opts.
assign (
"state", tst);
886 m_debug_on_error =
false;
889 m_debug_on_warning =
false;
897 const std::string&
id,
899 const std::list<frame_info>& stack_info_arg)
901 std::list<frame_info> stack_info = stack_info_arg;
903 if (stack_info.empty ())
912 stack_info.unique ();
930 std::string
message = ee.message ();
954OCTAVE_END_NAMESPACE(octave)
957vmessage (
const char *name,
const char *fmt, va_list args)
962 message = std::string (name) +
": ";
964 message += format_message (fmt, args);
967 std::cerr <<
message << std::endl;
971message (
const char *name,
const char *fmt, ...)
974 va_start (args, fmt);
982 octave::error_system& es = octave::__get_error_system__ ();
984 es.vusage (
id, fmt, args);
991 va_start (args, fmt);
999 error_1 (
"", fmt, args);
1006 va_start (args, fmt);
1012verror (octave::execution_exception& ee,
const char *fmt, va_list args)
1014 error_1 (ee,
"", fmt, args);
1018error (octave::execution_exception& ee,
const char *fmt, ...)
1021 va_start (args, fmt);
1029 error_1 (
"", fmt, args);
1036 va_start (args, fmt);
1044 error_1 (
id, fmt, args);
1051 va_start (args, fmt);
1059 error_1 (
id, fmt, args);
1066 va_start (args, fmt);
1072vwarning (
const char *fmt, va_list args)
1074 vwarning (
"", fmt, args);
1081 va_start (args, fmt);
1082 vwarning (fmt, args);
1089 vwarning (
id, fmt, args);
1096 va_start (args, fmt);
1097 vwarning (
id, fmt, args);
1104 error_1 (
"", fmt, args);
1111 va_start (args, fmt);
1119 error_1 (
id, fmt, args);
1126 va_start (args, fmt);
1134defun_usage_message (
const std::string& msg)
1136 ::defun_usage_message (
"%s", msg.c_str ());
1157 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1162 octave_map err_stack = init_error_stack (interp);
1282 int nargin = args.
length ();
1291 std::list<frame_info> stack_info;
1293 bool have_fmt =
false;
1295 if (nargin == 1 && args(0).isstruct ())
1298 if (args(0).isempty ())
1336 have_fmt = maybe_extract_message_id (
"error", args, nargs,
id);
1338 if (nargs.
length () == 0)
1339 message =
"unspecified error";
1496 int nargin = args.
length ();
1505 std::string arg1 = argv[1];
1506 std::transform (arg1.begin (), arg1.end (), arg1.begin (), tolower);
1507 std::string arg2 =
"all";
1508 std::string arg2_lc =
"all";
1514 std::transform (arg2_lc.begin (), arg2_lc.end (), arg2_lc.begin (),
1518 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1522 if (arg2_lc ==
"all")
1529 std::string arg3_lc = argv[3];
1530 std::transform (arg3_lc.begin (), arg3_lc.end (),
1531 arg3_lc.begin (), tolower);
1552 fields(0) =
"identifier";
1553 fields(1) =
"state";
1564 for (i = 0; i < nel; i++)
1566 std::string
id = ids(i).string_value ();
1570 states(i) = curr_state;
1584 states(nel) = curr_state;
1599 && (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error"))
1600 || (nargin >= 2 && arg2_lc ==
"all"))
1603 if (arg1 ==
"error")
1604 error (R
"(warning: cannot specify "all" warning ID with state "error")");
1614 tmp.
assign (
"identifier",
id);
1615 tmp.
assign (
"state", st);
1621 else if (arg2_lc ==
"backtrace")
1623 if (arg1 !=
"error")
1629 else if (arg2_lc ==
"debug")
1631 if (arg1 !=
"error")
1637 else if (arg2_lc ==
"verbose")
1639 if (arg1 !=
"error")
1645 else if (arg2_lc ==
"quiet")
1647 if (arg1 !=
"error")
1655 if (arg2_lc ==
"last")
1663 if (done && nargout > 0)
1664 retval = old_warning_options;
1666 else if (arg1 ==
"query")
1668 if (arg2_lc ==
"all")
1675 else if (arg2_lc ==
"backtrace" || arg2_lc ==
"debug"
1676 || arg2_lc ==
"verbose" || arg2_lc ==
"quiet")
1681 tmp.
assign (
"identifier", arg2_lc);
1682 if (arg2_lc ==
"backtrace")
1684 else if (arg2_lc ==
"debug")
1686 else if (arg2_lc ==
"verbose")
1695 if (arg2_lc ==
"backtrace")
1699 else if (arg2_lc ==
"debug")
1703 else if (arg2_lc ==
"verbose")
1721 octave_stdout <<
'"' << arg2 << R
"(" warning state is ")" <<
1730 else if (nargin == 0)
1739 else if (nargin == 1)
1750 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1761 Cell oldstate (state);
1765 std::string tid = ident(i).string_value ();
1768 old_warning_options.
setfield (
"state", oldstate);
1773 std::string tst = state(i).string_value ();
1774 std::string tid = ident(i).string_value ();
1782 retval = old_warning_options;
1792 bool have_fmt = maybe_extract_message_id (
"warning", args, nargs,
id);
1797 "unspecified warning", nargs,
1918 int nargin = args.
length ();
1936 if (args(0).is_string ())
1938 if (args(0).string_value () !=
"reset")
1939 error (
"lasterror: unrecognized string argument");
1946 else if (args(0).isstruct ())
1950 std::string new_error_message;
1951 std::string new_error_id;
1952 std::string new_error_file;
1953 std::string new_error_name;
1954 int new_error_line = -1;
1955 int new_error_column = -1;
1956 bool initialize_stack =
false;
1960 const std::string tmp
1962 new_error_message = tmp;
1965 if (new_err.
contains (
"identifier"))
1967 const std::string tmp
1975 initialize_stack =
true;
1981 if (new_err_stack.
contains (
"file"))
1983 const std::string tmp
1985 new_error_file = tmp;
1988 if (new_err_stack.
contains (
"name"))
1990 const std::string tmp
1992 new_error_name = tmp;
1995 if (new_err_stack.
contains (
"line"))
1999 new_error_line = tmp;
2002 if (new_err_stack.
contains (
"column"))
2006 new_error_column = tmp;
2014 if (initialize_stack)
2016 else if (new_err.
contains (
"stack"))
2018 new_err_stack.
setfield (
"file", new_error_file);
2019 new_err_stack.
setfield (
"name", new_error_name);
2020 new_err_stack.
setfield (
"line", new_error_line);
2021 new_err_stack.
setfield (
"column", new_error_column);
2029 error (
"lasterror: argument must be a structure or a string");
2048DEFMETHOD (lasterr, interp, args, nargout,
2064 int nargin = args.
length ();
2081 else if (nargin == 1)
2087 if (nargin == 0 || nargout > 0)
2088 return ovl (prev_error_message, prev_error_id);
2093DEFMETHOD (lastwarn, interp, args, nargout,
2109 int nargin = args.
length ();
2126 else if (nargin == 1)
2132 if (nargin == 0 || nargout > 0)
2133 return ovl (prev_warning_message, prev_warning_id);
2138DEFMETHOD (beep_on_error, interp, args, nargout,
2156DEFMETHOD (debug_on_error, interp, args, nargout,
2178DEFMETHOD (debug_on_warning, interp, args, nargout,
2205OCTAVE_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)
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
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__()
F77_RET_T const F77_DBLE const F77_DBLE * f
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)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)