26 #if defined (HAVE_CONFIG_H)
43 #include "builtin-defun-decls.h"
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);
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);
128 typedef void (*
error_fcn)(
const char *,
const char *, ...);
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 ());
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";
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),
268 m_last_error_message (),
269 m_last_warning_message (),
270 m_last_warning_id (),
303 "discard_warning_messages");
318 "backtrace_on_warning");
339 "last_error_message");
347 "last_warning_message");
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 ();
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 ()));
439 bool all_found =
false;
440 bool id_found =
false;
447 if (! all_found && ovs ==
"all")
455 if (! id_found && ovs ==
id)
463 if (all_found && id_found)
477 else if (all_state == 1)
479 if (id_state == 0 || id_state == 2)
484 else if (all_state == 2)
497 std::string str_id =
id ? id :
"";
504 const char *fmt, va_list args)
509 std::string msg_string;
512 msg_string = std::string (name) +
": ";
514 msg_string += base_msg;
516 bool fmt_suppresses_backtrace =
false;
517 std::size_t fmt_len = (fmt ?
strlen (fmt) : 0);
518 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
520 if (! fmt_suppresses_backtrace)
536 std::cerr << msg_string;
538 if (! fmt_suppresses_backtrace && in_user_code
544 if (! bt_msg.empty ())
545 bt_msg =
"warning: called from\n" + bt_msg;
548 std::cerr << bt_msg << std::endl;
565 const char *fmt, va_list args)
567 ee.set_identifier (
id);
578 std::list<frame_info> stack_info;
593 else if (warn_opt == 1)
594 vwarning (
"warning",
id, fmt, args);
598 const std::string& msg,
601 std::list<frame_info> stack_info;
609 error (
"rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
631 std::cerr <<
"panic: " <<
format_message (fmt, args) << std::endl;
639 va_start (args, fmt);
648 std::string
id = id_arg;
668 if (ident(i).string_value () ==
id)
670 val =
state(i).string_value ();
680 if (ident(i).string_value () ==
"all")
682 val =
state(i).string_value ();
694 retval.
assign (
"identifier",
id);
695 retval.
assign (
"state", val);
702 std::string retval =
"on";
713 if (ident(i).string_value () ==
"all")
715 retval =
state(i).string_value ();
734 if (all_state ==
"on")
735 os <<
"By default, warnings are enabled.";
736 else if (all_state ==
"off")
737 os <<
"By default, warnings are disabled.";
738 else if (all_state ==
"error")
739 os <<
"By default, warnings are treated as errors.";
746 os <<
"Non-default warning states are:\n\n";
747 os <<
" State Warning ID\n";
754 std::string tid = ident(i).string_value ();
755 std::string tst =
state(i).string_value ();
757 os << std::setw (7) << tst <<
" " << tid <<
"\n";
764 const std::string& ident)
769 error (
"invalid warning state: %s",
state.c_str ());
780 if (tid(i).string_value () == ident)
786 if (
state == all_state && ident !=
"all")
788 for (i = i + 1; i < nel; i++)
802 opts.
assign (
"identifier", tid);
803 opts.
assign (
"state", tst);
821 opts.
assign (
"identifier", tid);
822 opts.
assign (
"state", tst);
865 const std::string&
id,
867 const std::list<frame_info>& stack_info_arg)
869 std::list<frame_info> stack_info = stack_info_arg;
871 if (stack_info.empty ())
880 stack_info.unique ();
896 std::string
message = ee.message ();
906 std::ostream& os)
const
933 vmessage (
const char *name,
const char *fmt, va_list args)
938 message = std::string (name) +
": ";
943 std::cerr <<
message << std::endl;
947 message (
const char *name,
const char *fmt, ...)
950 va_start (args, fmt);
960 es.vusage (
id, fmt, args);
967 va_start (args, fmt);
982 va_start (args, fmt);
988 verror (octave::execution_exception& ee,
const char *fmt, va_list args)
994 error (octave::execution_exception& ee,
const char *fmt, ...)
997 va_start (args, fmt);
1012 va_start (args, fmt);
1027 va_start (args, fmt);
1042 va_start (args, fmt);
1057 va_start (args, fmt);
1072 va_start (args, fmt);
1087 va_start (args, fmt);
1102 va_start (args, fmt);
1113 es.vpanic (fmt, args);
1121 va_start (args, fmt);
1146 if (args.length () != 1)
1152 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1261 int nargin = args.length ();
1270 std::list<frame_info> stack_info;
1272 bool have_fmt =
false;
1274 if (nargin == 1 && args(0).isstruct ())
1277 if (args(0).isempty ())
1283 if (
m.nfields () == 0)
1286 if (
m.contains (
"message"))
1294 if (
m.contains (
"identifier"))
1302 if (
m.contains (
"stack"))
1317 if (nargs.
length () == 0)
1318 message =
"unspecified error";
1475 int nargin = args.
length ();
1480 if (nargin > 0 && args.all_strings_p ())
1484 std::string arg1 = argv[1];
1485 std::transform (arg1.begin (), arg1.end (), arg1.begin (), tolower);
1486 std::string arg2 =
"all";
1487 std::string arg2_lc =
"all";
1493 std::transform (arg2_lc.begin (), arg2_lc.end (), arg2_lc.begin (),
1497 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1501 if (arg2_lc ==
"all")
1508 std::string arg3_lc = argv[3];
1510 arg3_lc.begin (), tolower);
1511 if (arg3_lc ==
"local" && ! interp.at_top_level ())
1531 fields(0) =
"identifier";
1532 fields(1) =
"state";
1537 Cell ids =
m.contents (
"identifier");
1538 Cell states =
m.contents (
"state");
1543 for (i = 0; i < nel; i++)
1545 std::string
id = ids(i).string_value ();
1549 states(i) = curr_state;
1563 states(nel) = curr_state;
1566 m.contents (
"identifier") = ids;
1567 m.contents (
"state") = states;
1578 && (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error"))
1579 || (nargin >= 2 && arg2_lc ==
"all"))
1582 if (arg1 ==
"error")
1583 error (R
"(warning: cannot specify "all" warning ID with state "error")");
1593 tmp.
assign (
"identifier",
id);
1594 tmp.
assign (
"state", st);
1600 else if (arg2_lc ==
"backtrace")
1602 if (arg1 !=
"error")
1608 else if (arg2_lc ==
"debug")
1610 if (arg1 !=
"error")
1616 else if (arg2_lc ==
"verbose")
1618 if (arg1 !=
"error")
1624 else if (arg2_lc ==
"quiet")
1626 if (arg1 !=
"error")
1634 if (arg2_lc ==
"last")
1642 if (done && nargout > 0)
1643 retval = old_warning_options;
1645 else if (arg1 ==
"query")
1647 if (arg2_lc ==
"all")
1654 else if (arg2_lc ==
"backtrace" || arg2_lc ==
"debug"
1655 || arg2_lc ==
"verbose" || arg2_lc ==
"quiet")
1660 tmp.
assign (
"identifier", arg2_lc);
1661 if (arg2_lc ==
"backtrace")
1663 else if (arg2_lc ==
"debug")
1665 else if (arg2_lc ==
"verbose")
1674 if (arg2_lc ==
"backtrace")
1678 else if (arg2_lc ==
"debug")
1682 else if (arg2_lc ==
"verbose")
1700 octave_stdout <<
'"' << arg2 << R
"(" warning state is ")" <<
1709 else if (nargin == 0)
1718 else if (nargin == 1)
1728 if (!
m.contains (
"identifier") || !
m.contains (
"state"))
1729 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1733 Cell ident =
m.contents (
"identifier");
1744 std::string tid = ident(i).string_value ();
1747 old_warning_options.
setfield (
"state", oldstate);
1752 std::string tst =
state(i).string_value ();
1753 std::string tid = ident(i).string_value ();
1761 retval = old_warning_options;
1776 "unspecified warning", nargs,
1897 int nargin = args.length ();
1915 if (args(0).is_string ())
1917 if (args(0).string_value () !=
"reset")
1918 error (
"lasterror: unrecognized string argument");
1925 else if (args(0).isstruct ())
1929 std::string new_error_message;
1930 std::string new_error_id;
1931 std::string new_error_file;
1932 std::string new_error_name;
1933 int new_error_line = -1;
1934 int new_error_column = -1;
1935 bool initialize_stack =
false;
1939 const std::string tmp
1941 new_error_message = tmp;
1944 if (new_err.
contains (
"identifier"))
1946 const std::string tmp
1954 initialize_stack =
true;
1960 if (new_err_stack.
contains (
"file"))
1962 const std::string tmp
1964 new_error_file = tmp;
1967 if (new_err_stack.
contains (
"name"))
1969 const std::string tmp
1971 new_error_name = tmp;
1974 if (new_err_stack.
contains (
"line"))
1978 new_error_line = tmp;
1981 if (new_err_stack.
contains (
"column"))
1985 new_error_column = tmp;
1993 if (initialize_stack)
1995 else if (new_err.
contains (
"stack"))
1997 new_err_stack.
setfield (
"file", new_error_file);
1998 new_err_stack.
setfield (
"name", new_error_name);
1999 new_err_stack.
setfield (
"line", new_error_line);
2000 new_err_stack.
setfield (
"column", new_error_column);
2008 error (
"lasterror: argument must be a structure or a string");
2027 DEFMETHOD (lasterr, interp, args, nargout,
2043 int nargin = args.length ();
2060 else if (nargin == 1)
2066 if (nargin == 0 || nargout > 0)
2067 return ovl (prev_error_message, prev_error_id);
2072 DEFMETHOD (lastwarn, interp, args, nargout,
2088 int nargin = args.length ();
2105 else if (nargin == 1)
2111 if (nargin == 0 || nargout > 0)
2112 return ovl (prev_warning_message, prev_warning_id);
2117 DEFMETHOD (beep_on_error, interp, args, nargout,
2135 DEFMETHOD (debug_on_error, interp, args, nargout,
2157 DEFMETHOD (debug_on_warning, interp, args, nargout,
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Cell column(octave_idx_type i) const
static bool forced_interactive(void)
bool debug_on_warn(const std::string &id)
Vector representing the dimensions (size) of an Array.
bool m_backtrace_on_warning
TRUE means that Octave will try to display a stack trace when a warning is encountered.
bool quiet_warning(void) const
OCTINTERP_API error_system(interpreter &interp)
OCTINTERP_API void initialize_default_warning_state(void)
OCTINTERP_API octave_value beep_on_error(const octave_value_list &args, int nargout)
bool m_discard_warning_messages
TRUE means warning messages are turned off.
std::string m_last_error_id
The last error message id.
bool backtrace_on_warning(void) const
OCTINTERP_API void interpreter_try(unwind_protect &frame)
OCTINTERP_API void display_warning_options(std::ostream &os)
std::string last_error_message(void) const
static OCTINTERP_API std::list< frame_info > make_stack_frame_list(const octave_map &stack)
OCTINTERP_API octave_value last_error_id(const octave_value_list &args, int nargout)
OCTAVE_NORETURN OCTINTERP_API void error_1(execution_exception &ee, const char *id, const char *fmt, va_list args)
OCTAVE_NORETURN OCTINTERP_API void vpanic(const char *fmt, va_list args)
OCTINTERP_API octave_value quiet_warning(const octave_value_list &args, int nargout)
std::string m_last_error_message
The text of the last error message.
OCTINTERP_API void set_warning_option(const std::string &state, const std::string &id)
bool debug_on_caught(void) const
OCTAVE_NORETURN OCTINTERP_API void rethrow_error(const std::string &id, const std::string &msg, const octave_map &stack)
OCTINTERP_API octave_scalar_map warning_query(const std::string &id_arg)
octave_map warning_options(void) const
OCTINTERP_API octave_value backtrace_on_warning(const octave_value_list &args, int nargout)
std::string last_error_id(void) const
OCTINTERP_API octave_value last_warning_message(const octave_value_list &args, int nargout)
OCTAVE_NORETURN OCTINTERP_API 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 >())
std::string last_warning_id(void) const
OCTINTERP_API 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 m_last_warning_id
The last warning message id.
static OCTINTERP_API octave_map make_stack_map(const std::list< frame_info > &frames)
bool beep_on_error(void) const
bool discard_warning_messages(void) const
OCTAVE_NORETURN OCTINTERP_API void vusage(const char *id, const char *fmt, va_list args)
OCTINTERP_API octave_value debug_on_warning(const octave_value_list &args, int nargout)
OCTINTERP_API octave_value verbose_warning(const octave_value_list &args, int nargout)
bool m_debug_on_caught
TRUE means that Octave will try to enter the debugger when an error is encountered within the 'try' s...
bool m_debug_on_warning
TRUE means that Octave will try to enter the debugger when a warning is encountered.
OCTINTERP_API void display_exception(const execution_exception &ee, std::ostream &os) const
OCTINTERP_API void disable_warning(const std::string &id)
OCTINTERP_API void vwarning(const char *name, const char *id, const char *fmt, va_list args)
bool debug_on_warning(void) const
OCTINTERP_API octave_value last_warning_id(const octave_value_list &args, int nargout)
bool debug_on_error(void) const
OCTINTERP_API void save_exception(const execution_exception &ee)
OCTINTERP_API octave_value debug_on_error(const octave_value_list &args, int nargout)
bool m_beep_on_error
TRUE means that Octave will try to beep obnoxiously before printing error messages.
std::string last_warning_message(void) const
OCTINTERP_API octave_value last_error_message(const octave_value_list &args, int nargout)
bool m_debug_on_error
TRUE means that Octave will try to enter the debugger when an error is encountered.
interpreter & m_interpreter
bool m_quiet_warning
TRUE means that Octave will print no warnings, but lastwarn will be updated.
bool m_verbose_warning
TRUE means that Octave will print a verbose warning.
octave_map last_error_stack(void) const
OCTINTERP_API std::string default_warning_state(void)
OCTAVE_NORETURN OCTINTERP_API void panic(const char *fmt,...)
std::string m_last_warning_message
The text of the last warning message.
bool verbose_warning(void) const
Provides threadsafe access to octave.
bool display_exception(const execution_exception &ee, bool beep=false)
event_manager & get_event_manager(void)
tree_evaluator & get_evaluator(void)
bool interactive(void) const
void setfield(const std::string &key, const Cell &val)
octave_idx_type numel(void) 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())
octave_idx_type length(void) const
OCTINTERP_API octave_scalar_map scalar_map_value(void) const
OCTINTERP_API octave_map xmap_value(const char *fmt,...) const
bool is_string(void) const
bool is_defined(void) const
bool isstruct(void) const
std::string string_value(bool force=false) const
int nint_value(bool frc_str_conv=false) const
OCTINTERP_API octave_map map_value(void) const
OCTINTERP_API octave_idx_type length(void) const
octave_map empty_backtrace(void) const
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
octave_map backtrace(octave_idx_type &curr_user_frame, bool print_subfn=true) const
bool in_user_code(void) const
std::string backtrace_message(void) 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> ")
bp_table & get_bp_table(void)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#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,...)
static const octave_fields bt_fields(bt_fieldnames)
static int check_state(const std::string &state)
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,...)
OCTAVE_EXPORT octave_value_list Fwarning(octave::interpreter &interp, const octave_value_list &args, int nargout)
static OCTAVE_NORETURN void error_1(octave::execution_exception &ee, const char *id, const char *fmt, va_list args)
static void vwarning(const char *id, 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)
static const char * bt_fieldnames[]
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,...)
static void defun_usage_message(const char *fmt,...)
void error(const char *fmt,...)
static std::string format_message(const char *fmt, va_list args)
static std::string handle_message(error_fcn f, const char *id, const char *msg, const octave_value_list &args, bool have_fmt)
void vparse_error(const char *fmt, va_list args)
static octave_map init_error_stack(interpreter &interp)
static bool maybe_extract_message_id(const std::string &caller, const octave_value_list &args, octave_value_list &nargs, std::string &id)
void message(const char *name, const char *fmt,...)
static octave_scalar_map init_warning_options(const std::string &state)
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)
void panic_unless(bool cond)
#define panic_impossible()
OCTAVE_EXPORT octave_value_list Fsprintf(const octave_value_list &args, int)
ColumnVector transform(const Matrix &m, double x, double y, double z)
error_system & __get_error_system__(void)
interpreter & __get_interpreter__(void)
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.
static uint32_t state[624]
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)