26 #if defined (HAVE_CONFIG_H)
62 format_message (
const char *fmt, va_list args)
67 std::ostringstream output_buf;
71 return output_buf.str ();
76 error_1 (octave::execution_exception& ee,
const char *
id,
const char *fmt,
81 es.error_1 (ee,
id, fmt, args);
86 error_1 (
const char *
id,
const char *fmt, va_list args)
90 es.error_1 (
id, fmt, args);
94 check_state (
const std::string& state)
103 else if (state ==
"on")
105 else if (state ==
"error")
112 vwarning (
const char *
id,
const char *fmt, va_list args)
116 es.vwarning (
id, fmt, args);
123 va_start (args, fmt);
124 error_1 (
"", fmt, args);
128 typedef void (*
error_fcn)(
const char *,
const char *, ...);
131 handle_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 ());
192 maybe_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";
239 init_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");
366 static 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 ();
390 column(k) = frm.
column ();
398 std::list<frame_info>
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)
511 std::string base_msg = format_message (fmt, args);
512 std::string msg_string;
515 msg_string = std::string (name) +
": ";
517 msg_string += base_msg;
519 bool fmt_suppresses_backtrace =
false;
520 std::size_t fmt_len = (fmt ?
strlen (fmt) : 0);
521 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
523 if (! fmt_suppresses_backtrace)
539 std::cerr << msg_string;
541 if (! fmt_suppresses_backtrace && in_user_code
547 if (! bt_msg.empty ())
548 bt_msg =
"warning: called from\n" + bt_msg;
551 std::cerr << bt_msg << std::endl;
569 const char *fmt, va_list args)
571 ee.set_identifier (
id);
572 ee.set_message (format_message (fmt, args));
581 std::string
message = format_message (fmt, args);
583 std::list<frame_info> stack_info;
599 else if (warn_opt == 1)
600 vwarning (
"warning",
id, fmt, args);
605 const std::string& msg,
608 std::list<frame_info> stack_info;
616 error (
"rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
639 std::cerr <<
"panic: " << format_message (fmt, args) << std::endl;
648 va_start (args, fmt);
658 std::string
id = id_arg;
678 if (ident(i).string_value () ==
id)
680 val = state(i).string_value ();
690 if (ident(i).string_value () ==
"all")
692 val = state(i).string_value ();
704 retval.
assign (
"identifier",
id);
705 retval.
assign (
"state", val);
713 std::string retval =
"on";
724 if (ident(i).string_value () ==
"all")
726 retval = state(i).string_value ();
746 if (all_state ==
"on")
747 os <<
"By default, warnings are enabled.";
748 else if (all_state ==
"off")
749 os <<
"By default, warnings are disabled.";
750 else if (all_state ==
"error")
751 os <<
"By default, warnings are treated as errors.";
758 os <<
"Non-default warning states are:\n\n";
759 os <<
" State Warning ID\n";
766 std::string tid = ident(i).string_value ();
767 std::string tst = state(i).string_value ();
769 os << std::setw (7) << tst <<
" " << tid <<
"\n";
777 const std::string& ident)
781 if (state !=
"on" && state !=
"off" && state !=
"error")
782 error (
"invalid warning state: %s", state.c_str ());
793 if (tid(i).string_value () == ident)
799 if (state == all_state && ident !=
"all")
801 for (i = i + 1; i < nel; i++)
815 opts.
assign (
"identifier", tid);
816 opts.
assign (
"state", tst);
834 opts.
assign (
"identifier", tid);
835 opts.
assign (
"state", tst);
871 m_debug_on_error =
false;
874 m_debug_on_warning =
false;
882 const std::string&
id,
884 const std::list<frame_info>& stack_info_arg)
886 std::list<frame_info> stack_info = stack_info_arg;
888 if (stack_info.empty ())
897 stack_info.unique ();
915 std::string
message = ee.message ();
939 OCTAVE_END_NAMESPACE(
octave)
942 vmessage (
const char *name,
const char *fmt, va_list args)
947 message = std::string (name) +
": ";
949 message += format_message (fmt, args);
952 std::cerr <<
message << std::endl;
956 message (
const char *name,
const char *fmt, ...)
959 va_start (args, fmt);
969 es.vusage (
id, fmt, args);
976 va_start (args, fmt);
984 error_1 (
"", fmt, args);
988 error (
const char *fmt, ...)
991 va_start (args, fmt);
997 verror (octave::execution_exception& ee,
const char *fmt, va_list args)
999 error_1 (ee,
"", fmt, args);
1003 error (octave::execution_exception& ee,
const char *fmt, ...)
1006 va_start (args, fmt);
1014 error_1 (
"", fmt, args);
1021 va_start (args, fmt);
1029 error_1 (
id, fmt, args);
1036 va_start (args, fmt);
1044 error_1 (
id, fmt, args);
1051 va_start (args, fmt);
1066 va_start (args, fmt);
1081 va_start (args, fmt);
1089 error_1 (
"", fmt, args);
1096 va_start (args, fmt);
1104 error_1 (
id, fmt, args);
1111 va_start (args, fmt);
1122 es.vpanic (fmt, args);
1130 va_start (args, fmt);
1161 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1166 octave_map err_stack = init_error_stack (interp);
1270 int nargin = args.
length ();
1279 std::list<frame_info> stack_info;
1281 bool have_fmt =
false;
1283 if (nargin == 1 && args(0).isstruct ())
1286 if (args(0).isempty ())
1292 if (
m.nfields () == 0)
1295 if (
m.contains (
"message"))
1303 if (
m.contains (
"identifier"))
1311 if (
m.contains (
"stack"))
1324 have_fmt = maybe_extract_message_id (
"error", args, nargs,
id);
1326 if (nargs.
length () == 0)
1327 message =
"unspecified error";
1484 int nargin = args.
length ();
1493 std::string arg1 = argv[1];
1494 std::transform (arg1.begin (), arg1.end (), arg1.begin (), tolower);
1495 std::string arg2 =
"all";
1496 std::string arg2_lc =
"all";
1502 std::transform (arg2_lc.begin (), arg2_lc.end (), arg2_lc.begin (),
1506 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1510 if (arg2_lc ==
"all")
1517 std::string arg3_lc = argv[3];
1519 arg3_lc.begin (), tolower);
1540 fields(0) =
"identifier";
1541 fields(1) =
"state";
1546 Cell ids =
m.contents (
"identifier");
1547 Cell states =
m.contents (
"state");
1552 for (i = 0; i < nel; i++)
1554 std::string
id = ids(i).string_value ();
1558 states(i) = curr_state;
1572 states(nel) = curr_state;
1575 m.contents (
"identifier") = ids;
1576 m.contents (
"state") = states;
1587 && (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error"))
1588 || (nargin >= 2 && arg2_lc ==
"all"))
1591 if (arg1 ==
"error")
1592 error (R
"(warning: cannot specify "all" warning ID with state "error")");
1602 tmp.
assign (
"identifier",
id);
1603 tmp.
assign (
"state", st);
1609 else if (arg2_lc ==
"backtrace")
1611 if (arg1 !=
"error")
1617 else if (arg2_lc ==
"debug")
1619 if (arg1 !=
"error")
1625 else if (arg2_lc ==
"verbose")
1627 if (arg1 !=
"error")
1633 else if (arg2_lc ==
"quiet")
1635 if (arg1 !=
"error")
1643 if (arg2_lc ==
"last")
1651 if (done && nargout > 0)
1652 retval = old_warning_options;
1654 else if (arg1 ==
"query")
1656 if (arg2_lc ==
"all")
1663 else if (arg2_lc ==
"backtrace" || arg2_lc ==
"debug"
1664 || arg2_lc ==
"verbose" || arg2_lc ==
"quiet")
1669 tmp.
assign (
"identifier", arg2_lc);
1670 if (arg2_lc ==
"backtrace")
1672 else if (arg2_lc ==
"debug")
1674 else if (arg2_lc ==
"verbose")
1683 if (arg2_lc ==
"backtrace")
1687 else if (arg2_lc ==
"debug")
1691 else if (arg2_lc ==
"verbose")
1709 octave_stdout <<
'"' << arg2 << R
"(" warning state is ")" <<
1718 else if (nargin == 0)
1727 else if (nargin == 1)
1737 if (!
m.contains (
"identifier") || !
m.contains (
"state"))
1738 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1742 Cell ident =
m.contents (
"identifier");
1743 Cell state =
m.contents (
"state");
1749 Cell oldstate (state);
1753 std::string tid = ident(i).string_value ();
1756 old_warning_options.
setfield (
"state", oldstate);
1761 std::string tst = state(i).string_value ();
1762 std::string tid = ident(i).string_value ();
1770 retval = old_warning_options;
1780 bool have_fmt = maybe_extract_message_id (
"warning", args, nargs,
id);
1785 "unspecified warning", nargs,
1906 int nargin = args.
length ();
1924 if (args(0).is_string ())
1926 if (args(0).string_value () !=
"reset")
1927 error (
"lasterror: unrecognized string argument");
1934 else if (args(0).isstruct ())
1938 std::string new_error_message;
1939 std::string new_error_id;
1940 std::string new_error_file;
1941 std::string new_error_name;
1942 int new_error_line = -1;
1943 int new_error_column = -1;
1944 bool initialize_stack =
false;
1948 const std::string tmp
1950 new_error_message = tmp;
1953 if (new_err.
contains (
"identifier"))
1955 const std::string tmp
1963 initialize_stack =
true;
1969 if (new_err_stack.
contains (
"file"))
1971 const std::string tmp
1973 new_error_file = tmp;
1976 if (new_err_stack.
contains (
"name"))
1978 const std::string tmp
1980 new_error_name = tmp;
1983 if (new_err_stack.
contains (
"line"))
1987 new_error_line = tmp;
1990 if (new_err_stack.
contains (
"column"))
1994 new_error_column = tmp;
2002 if (initialize_stack)
2004 else if (new_err.
contains (
"stack"))
2006 new_err_stack.
setfield (
"file", new_error_file);
2007 new_err_stack.
setfield (
"name", new_error_name);
2008 new_err_stack.
setfield (
"line", new_error_line);
2009 new_err_stack.
setfield (
"column", new_error_column);
2017 error (
"lasterror: argument must be a structure or a string");
2036 DEFMETHOD (lasterr, interp, args, nargout,
2052 int nargin = args.
length ();
2069 else if (nargin == 1)
2075 if (nargin == 0 || nargout > 0)
2076 return ovl (prev_error_message, prev_error_id);
2081 DEFMETHOD (lastwarn, interp, args, nargout,
2097 int nargin = args.
length ();
2114 else if (nargin == 1)
2120 if (nargin == 0 || nargout > 0)
2121 return ovl (prev_warning_message, prev_warning_id);
2126 DEFMETHOD (beep_on_error, interp, args, nargout,
2144 DEFMETHOD (debug_on_error, interp, args, nargout,
2166 DEFMETHOD (debug_on_warning, interp, args, nargout,
2193 OCTAVE_END_NAMESPACE(
octave)
octave_value_list Fwarning(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fsprintf(const octave_value_list &=octave_value_list(), int=0)
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 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)
bool at_top_level() const
event_manager & get_event_manager()
tree_evaluator & get_evaluator()
error_system & get_error_system()
line(const graphics_handle &mh, const graphics_handle &p)
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 Cell & contents(const_iterator p) const
bool contains(const std::string &name) const
const octave_value & contents(const_iterator p) const
void setfield(const std::string &key, const octave_value &val)
void assign(const std::string &k, const octave_value &val)
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
std::string backtrace_message() const
std::list< frame_info > backtrace_info(octave_idx_type &curr_user_frame, bool print_subfn=true) const
bp_table & get_bp_table()
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 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,...)
OCTAVE_NORETURN void panic(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,...)
void vwarning(const char *fmt, va_list args)
OCTAVE_NORETURN void vpanic(const char *fmt, va_list args)
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 defun_usage_message(const std::string &msg)
Helper function for print_usage defined in defun.cc.
void vparse_error(const char *fmt, va_list args)
void message(const char *name, const char *fmt,...)
void vmessage(const char *name, const char *fmt, va_list args)
void interpreter_try(octave::unwind_protect &)
#define panic_impossible()
octave_value_list set_warning_state(const std::string &id, const std::string &state)
void disable_warning(const std::string &id)
#define panic_unless(cond)
int warning_enabled(const std::string &id)
ColumnVector transform(const Matrix &m, double x, double y, double z)
interpreter & __get_interpreter__()
error_system & __get_error_system__()
F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value_list Fsprintf(const octave_value_list &args, int)
std::size_t vformat(std::ostream &os, const char *fmt, va_list args)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
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.