26 #if defined (HAVE_CONFIG_H)
43 #include "builtin-defun-decls.h"
66 std::ostringstream output_buf;
70 return output_buf.str ();
75 error_1 (octave::execution_exception& e,
const char *
id,
const char *fmt,
85 error_1 (
const char *
id,
const char *fmt, va_list args)
102 else if (
state ==
"on")
104 else if (
state ==
"error")
111 vwarning (
const char *
id,
const char *fmt, va_list args)
122 va_start (args, fmt);
127 typedef void (*
error_fun)(
const char *,
const char *, ...);
156 msg = tmpstr.c_str ();
168 if (msg[
len - 1] ==
'\n')
172 std::string tmp_msg (msg,
len - 1);
173 f (
id,
"%s\n", tmp_msg.c_str ());
199 int nargin = args.
length ();
201 bool have_fmt = nargin > 1;
205 std::string arg1 = args(0).string_value ();
211 if (arg1.find_first_of (
"% \f\n\r\t\v") == std::string::npos
212 && arg1.find (
':') != std::string::npos
214 && arg1.back () !=
':')
222 for (
int i = 1; i < nargin; i++)
223 nargs(i-1) = args(i);
226 nargs(0) =
"call to " + caller
227 +
" with message identifier '" + arg1
228 +
"' requires message";
242 initw.
setfield (
"identifier",
"all");
257 : m_interpreter (interp),
258 m_debug_on_error (false),
259 m_debug_on_caught (false),
260 m_debug_on_warning (false),
261 m_discard_warning_messages (false),
262 m_beep_on_error (false),
263 m_backtrace_on_warning (true),
264 m_verbose_warning (false),
265 m_quiet_warning (false),
267 m_last_error_message (),
268 m_last_warning_message (),
269 m_last_warning_id (),
302 "discard_warning_messages");
317 "backtrace_on_warning");
338 "last_error_message");
346 "last_warning_message");
366 {
"file",
"name",
"line",
"column",
nullptr };
373 size_t nframes = frames.size ();
382 bool have_column =
false;
386 for (
const auto& frm : frames)
388 file(k) = frm.file_name ();
389 name(k) = frm.fcn_name ();
391 int c = frm.column ();
402 retval.rmfield (
"column");
407 std::list<octave::frame_info>
410 std::list<octave::frame_info> frames;
416 bool have_column =
false;
426 frames.push_back (octave::frame_info (file(i).string_value (),
427 name(i).string_value (),
428 line(i).int_value (),
430 ? column(i).int_value () : -1)));
455 bool all_found =
false;
456 bool id_found =
false;
463 if (! all_found && ovs ==
"all")
471 if (! id_found && ovs ==
id)
479 if (all_found && id_found)
493 else if (all_state == 1)
495 if (id_state == 0 || id_state == 2)
500 else if (all_state == 2)
513 std::string str_id =
id ? id :
"";
520 const char *fmt, va_list args)
525 std::string msg_string;
528 msg_string = std::string (
name) +
": ";
530 msg_string += base_msg;
532 bool fmt_suppresses_backtrace =
false;
533 size_t fmt_len = (fmt ?
strlen (fmt) : 0);
534 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
536 if (! fmt_suppresses_backtrace)
552 std::cerr << msg_string;
554 if (! fmt_suppresses_backtrace && in_user_code
560 if (! bt_msg.empty ())
561 bt_msg =
"warning: called from\n" + bt_msg;
564 std::cerr << bt_msg << std::endl;
584 const char *fmt, va_list args)
586 e.set_identifier (
id);
597 std::list<frame_info> stack_info;
612 else if (warn_opt == 1)
613 vwarning (
"warning",
id, fmt, args);
617 const std::string& msg,
620 std::list<frame_info> stack_info;
627 error (
"rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
640 std::cerr <<
"panic: " <<
format_message (fmt, args) << std::endl;
648 va_start (args, fmt);
657 std::string
id = id_arg;
677 if (ident(i).string_value () ==
id)
679 val =
state(i).string_value ();
689 if (ident(i).string_value () ==
"all")
691 val =
state(i).string_value ();
712 std::string
retval =
"on";
723 if (ident(i).string_value () ==
"all")
744 if (all_state ==
"on")
745 os <<
"By default, warnings are enabled.";
746 else if (all_state ==
"off")
747 os <<
"By default, warnings are disabled.";
748 else if (all_state ==
"error")
749 os <<
"By default, warnings are treated as errors.";
760 std::string tid = ident(i).string_value ();
761 std::string tst =
state(i).string_value ();
763 os << std::setw (7) << tst <<
" " << tid <<
"\n";
770 const std::string& ident)
775 error (
"invalid warning state: %s",
state.c_str ());
786 if (tid(i).string_value () == ident)
792 if (
state == all_state && ident !=
"all")
794 for (i = i + 1; i < nel; i++)
808 opts.
assign (
"identifier", tid);
809 opts.
assign (
"state", tst);
827 opts.
assign (
"identifier", tid);
828 opts.
assign (
"state", tst);
871 const std::string&
id,
873 const std::list<frame_info>& stack_info_arg)
875 std::list<frame_info> stack_info = stack_info_arg;
877 if (stack_info.empty ())
886 stack_info.unique ();
902 std::string
message = e.message ();
911 std::ostream& os)
const
932 std::cerr <<
message << std::endl;
939 va_start (args, fmt);
949 es.
vusage (
id, fmt, args);
956 va_start (args, fmt);
971 va_start (args, fmt);
977 verror (octave::execution_exception& e,
const char *fmt, va_list args)
983 error (octave::execution_exception& e,
const char *fmt, ...)
986 va_start (args, fmt);
1001 va_start (args, fmt);
1016 va_start (args, fmt);
1031 va_start (args, fmt);
1053 va_start (args, fmt);
1068 va_start (args, fmt);
1083 va_start (args, fmt);
1098 va_start (args, fmt);
1117 va_start (args, fmt);
1140 if (args.length () != 1)
1146 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1252 int nargin = args.length ();
1261 std::list<octave::frame_info> stack_info;
1263 bool have_fmt =
false;
1265 if (nargin == 1 && args(0).isstruct ())
1268 if (args(0).isempty ())
1274 if (
m.nfields () == 0)
1277 if (
m.contains (
"message"))
1285 if (
m.contains (
"identifier"))
1293 if (
m.contains (
"stack"))
1308 if (nargs.
length () == 0)
1309 message =
"unspecified error";
1466 int nargin = args.length ();
1471 if (nargin > 0 && args.all_strings_p ())
1475 std::string arg1 = argv[1];
1476 std::transform (arg1.begin (), arg1.end (), arg1.begin (), tolower);
1477 std::string arg2 =
"all";
1478 std::string arg2_lc =
"all";
1484 std::transform (arg2_lc.begin (), arg2_lc.end (), arg2_lc.begin (),
1488 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1492 if (arg2_lc ==
"all")
1499 std::string arg3_lc = argv[3];
1501 arg3_lc.begin (), tolower);
1502 if (arg3_lc ==
"local" && ! interp.at_top_level ())
1523 fields(0) =
"identifier";
1524 fields(1) =
"state";
1529 Cell ids =
m.contents (
"identifier");
1530 Cell states =
m.contents (
"state");
1535 for (i = 0; i < nel; i++)
1537 std::string
id = ids(i).string_value ();
1541 states(i) = curr_state;
1555 states(nel) = curr_state;
1558 m.contents (
"identifier") = ids;
1559 m.contents (
"state") = states;
1569 if (nargin >= 2 && arg2_lc ==
"all")
1574 int is_error = (arg1 ==
"error");
1576 Cell id (1, 1 + 2*is_error);
1577 Cell st (1, 1 + 2*is_error);
1589 id(1) =
"Octave:language-extension";
1592 id(2) =
"Octave:single-quote-string";
1596 tmp.
assign (
"identifier",
id);
1597 tmp.
assign (
"state", st);
1603 else if (arg2_lc ==
"backtrace")
1605 if (arg1 !=
"error")
1611 else if (arg2_lc ==
"debug")
1613 if (arg1 !=
"error")
1619 else if (arg2_lc ==
"verbose")
1621 if (arg1 !=
"error")
1627 else if (arg2_lc ==
"quiet")
1629 if (arg1 !=
"error")
1637 if (arg2_lc ==
"last")
1645 if (done && nargout > 0)
1646 retval = old_warning_options;
1648 else if (arg1 ==
"query")
1650 if (arg2_lc ==
"all")
1652 else if (arg2_lc ==
"backtrace" || arg2_lc ==
"debug"
1653 || arg2_lc ==
"verbose" || arg2_lc ==
"quiet")
1656 tmp.
assign (
"identifier", arg2_lc);
1657 if (arg2_lc ==
"backtrace")
1659 else if (arg2_lc ==
"debug")
1661 else if (arg2_lc ==
"verbose")
1674 else if (nargin == 0)
1683 else if (nargin == 1)
1693 if (!
m.contains (
"identifier") || !
m.contains (
"state"))
1694 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1698 Cell ident =
m.contents (
"identifier");
1709 std::string tid = ident(i).string_value ();
1712 old_warning_options.
setfield (
"state", oldstate);
1717 std::string tst =
state(i).string_value ();
1718 std::string tid = ident(i).string_value ();
1726 retval = old_warning_options;
1741 "unspecified warning", nargs,
1857 int nargin = args.length ();
1875 if (args(0).is_string ())
1877 if (args(0).string_value () !=
"reset")
1878 error (
"lasterror: unrecognized string argument");
1885 else if (args(0).isstruct ())
1889 std::string new_error_message;
1890 std::string new_error_id;
1891 std::string new_error_file;
1892 std::string new_error_name;
1893 int new_error_line = -1;
1894 int new_error_column = -1;
1895 bool initialize_stack =
false;
1899 const std::string tmp
1901 new_error_message = tmp;
1904 if (new_err.
contains (
"identifier"))
1906 const std::string tmp
1914 initialize_stack =
true;
1920 if (new_err_stack.
contains (
"file"))
1922 const std::string tmp
1924 new_error_file = tmp;
1927 if (new_err_stack.
contains (
"name"))
1929 const std::string tmp
1931 new_error_name = tmp;
1934 if (new_err_stack.
contains (
"line"))
1938 new_error_line = tmp;
1941 if (new_err_stack.
contains (
"column"))
1945 new_error_column = tmp;
1953 if (initialize_stack)
1955 else if (new_err.
contains (
"stack"))
1957 new_err_stack.
setfield (
"file", new_error_file);
1958 new_err_stack.
setfield (
"name", new_error_name);
1959 new_err_stack.
setfield (
"line", new_error_line);
1960 new_err_stack.
setfield (
"column", new_error_column);
1968 error (
"lasterror: argument must be a structure or a string");
1987 DEFMETHOD (lasterr, interp, args, nargout,
2003 int nargin = args.length ();
2020 else if (nargin == 1)
2026 if (nargin == 0 || nargout > 0)
2027 return ovl (prev_error_message, prev_error_id);
2032 DEFMETHOD (lastwarn, interp, args, nargout,
2048 int nargin = args.length ();
2065 else if (nargin == 1)
2071 if (nargin == 0 || nargout > 0)
2072 return ovl (prev_warning_message, prev_warning_id);
2077 DEFMETHOD (beep_on_error, interp, args, nargout,
2095 DEFMETHOD (debug_on_error, interp, args, nargout,
2117 DEFMETHOD (debug_on_warning, interp, args, nargout,
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
void assign(const idx_vector &i, const Array< T > &rhs, const T &rfv)
Indexed assignment (always with resize & fill).
octave_idx_type numel(void) const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
line(const graphics_handle &mh, const graphics_handle &p)
static bool forced_interactive(void)
bool debug_on_warn(const std::string &id)
std::string m_last_warning_message
The text of the last warning message.
bool m_discard_warning_messages
TRUE means warning messages are turned off.
std::string last_error_message(void) const
octave_value last_warning_id(const octave_value_list &args, int nargout)
void vwarning(const char *name, const char *id, const char *fmt, va_list args)
octave_value last_error_message(const octave_value_list &args, int nargout)
void disable_warning(const std::string &id)
void save_exception(const execution_exception &e)
void initialize_default_warning_state(void)
void display_warning_options(std::ostream &os)
std::string default_warning_state(void)
bool m_backtrace_on_warning
TRUE means that Octave will try to display a stack trace when a warning is encountered.
octave_value quiet_warning(const octave_value_list &args, int nargout)
octave_value debug_on_error(const octave_value_list &args, int nargout)
bool backtrace_on_warning(void) const
std::string m_last_warning_id
The last warning message id.
void set_warning_option(const std::string &state, const std::string &id)
octave_scalar_map warning_query(const std::string &id_arg)
std::string m_last_error_message
The text of the last error message.
std::string m_last_error_id
The last error message id.
octave_value last_warning_message(const octave_value_list &args, int nargout)
void display_exception(const execution_exception &e, std::ostream &os) const
std::string last_error_id(void) const
bool debug_on_caught(void) const
bool beep_on_error(void) const
octave_value beep_on_error(const octave_value_list &args, int nargout)
bool m_quiet_warning
TRUE means that Octave will print no warnings, but lastwarn will be updated.
OCTAVE_NORETURN void vusage(const char *id, const char *fmt, va_list args)
octave_value verbose_warning(const octave_value_list &args, int nargout)
OCTAVE_NORETURN void panic(const char *fmt,...)
bool discard_warning_messages(void) const
bool m_debug_on_warning
TRUE means that Octave will try to enter the debugger when a warning is encountered.
bool m_verbose_warning
TRUE means that Octave will print a verbose warning.
octave_value last_error_id(const octave_value_list &args, int nargout)
OCTAVE_NORETURN void vpanic(const char *fmt, va_list args)
octave_map warning_options(void) const
static std::list< octave::frame_info > make_stack_frame_list(const octave_map &stack)
OCTAVE_NORETURN void rethrow_error(const std::string &id, const std::string &msg, const octave_map &stack)
std::string last_warning_message(void) const
octave_value backtrace_on_warning(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.
bool debug_on_error(void) const
octave_map last_error_stack(void) const
octave_value debug_on_warning(const octave_value_list &args, int nargout)
OCTAVE_NORETURN void error_1(execution_exception &e, const char *id, const char *fmt, va_list args)
bool m_beep_on_error
TRUE means that Octave will try to beep obnoxiously before printing error messages.
std::string last_warning_id(void) const
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 verbose_warning(void) const
bool debug_on_warning(void) const
bool quiet_warning(void) const
void interpreter_try(octave::unwind_protect &frame)
error_system(interpreter &interp)
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 >())
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...
interpreter & m_interpreter
static octave_map make_stack_map(const std::list< octave::frame_info > &frames)
bool interactive(void) const
tree_evaluator & get_evaluator(void)
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val=octave_value())
bp_table & get_bp_table(void)
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
std::string backtrace_message(void) const
bool in_user_code(void) const
octave_map empty_backtrace(void) const
std::list< frame_info > backtrace_info(octave_idx_type &curr_user_frame, bool print_subfn=true) const
void enter_debugger(const std::string &prompt="debug> ")
octave_map backtrace(octave_idx_type &curr_user_frame, bool print_subfn=true) 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
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
octave_scalar_map scalar_map_value(void) const
octave_map map_value(void) const
OCTINTERP_API void print_usage(void)
#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,...)
static int check_state(const std::string &state)
std::string last_error_id(void)
void usage_with_id(const char *id, const char *fmt,...)
void warning(const char *fmt,...)
std::string last_warning_message(void)
void interpreter_try(octave::unwind_protect &frame)
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)
std::string last_error_message(void)
static void vwarning(const char *id, const char *fmt, va_list args)
OCTAVE_NORETURN void vpanic(const char *fmt, va_list args)
static std::string handle_message(error_fun f, const char *id, const char *msg, const octave_value_list &args, bool have_fmt)
octave_map last_error_stack(void)
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)
static OCTAVE_NORETURN void error_1(octave::execution_exception &e, const char *id, const char *fmt, va_list args)
void error_with_cfn(const char *fmt,...)
std::string last_warning_id(void)
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)
void vparse_error(const char *fmt, va_list args)
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,...)
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(* error_fun)(const char *, const char *,...)
void disable_warning(const std::string &id)
int warning_enabled(const std::string &id)
#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)
F77_RET_T const F77_DBLE const F77_DBLE * f
static const char * bt_fieldnames[]
static uint32_t state[624]
static const octave_fields bt_fields(bt_fieldnames)
static octave_scalar_map init_warning_options(const std::string &state)
error_system & __get_error_system__(const std::string &who)
interpreter & __get_interpreter__(const std::string &who)
size_t vformat(std::ostream &os, const char *fmt, va_list args)
static octave_map init_error_stack(interpreter &interp)
T::size_type strlen(const typename T::value_type *str)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)