23 #if defined (HAVE_CONFIG_H)
126 buffer_error_messages = 0;
128 discard_error_messages =
false;
136 initw.
setfield (
"identifier",
"all");
139 warning_options = initw;
149 verror (
bool save_last_error, std::ostream& os,
150 const char *
name,
const char *
id,
const char *fmt, va_list
args,
151 bool with_cfn =
false)
153 if (discard_error_messages && ! Vdebug_on_caught)
156 if (! buffer_error_messages || Vdebug_on_caught)
163 std::ostringstream output_buf;
173 if (to_beep_or_not_to_beep_p)
178 if (in_try_catch && !
strcmp (name,
"error"))
179 msg_string +=
"caught error: ";
197 if (cfn.length () > base_msg.length ()
198 || base_msg.compare (0, cfn.length (), cfn) != 0)
200 msg_string += cfn +
' ';
206 msg_string += base_msg +
"\n";
227 if (! buffer_error_messages || Vdebug_on_caught)
241 size_t len =
strlen (fmt);
245 if (fmt[len - 1] ==
'\n')
250 verror (
false, os, 0,
"", tmp_fmt.c_str (),
args);
254 verror (
false, os, 0,
"", fmt, args);
259 panic (
"pr_where_2: invalid format");
266 va_start (args, fmt);
281 const std::list<error_stack_frame>& frames)
283 size_t nframes = frames.size ();
288 for (std::list<error_stack_frame>::const_iterator
p = frames.begin ();
289 p != frames.end ();
p++)
301 fcn_name.c_str (), line,
column);
303 pr_where_1 (os,
" %s at line %d\n", fcn_name.c_str (), line);
313 std::list<octave_call_stack::stack_frame> call_stack_frames
318 call_stack_frames.unique ();
320 std::list<error_stack_frame> frames;
321 for (std::list<octave_call_stack::stack_frame>::const_iterator
p = call_stack_frames.begin ();
322 p != call_stack_frames.end ();
p++)
332 frames.push_back (frame);
338 static octave::execution_exception
341 std::ostringstream buf;
345 octave::execution_exception
retval;
347 retval.set_stack_trace (buf.str ());
354 bool show_stack_trace =
false)
356 if ((octave::application::interactive ()
357 || octave::application::forced_interactive ())
364 Vdebug_on_error =
false;
370 if (show_stack_trace)
374 if (! stack_trace.empty ())
376 std::cerr << stack_trace;
378 e.set_stack_trace ();
391 if (discard_warning_messages)
396 std::ostringstream output_buf;
410 msg_string += base_msg +
"\n";
415 if (! Vquiet_warning)
419 std::cerr << msg_string;
426 verror (
false, std::cerr, name,
"", fmt, args);
433 va_start (args, fmt);
442 verror (
false, std::cerr, name,
id, fmt, args);
449 va_start (args, fmt);
454 OCTAVE_NORETURN
static
456 usage_1 (octave::execution_exception&
e,
const char *
id,
457 const char *fmt, va_list
args)
459 verror (
true, std::cerr,
"usage",
id, fmt, args);
466 OCTAVE_NORETURN
static
485 va_start (args, fmt);
500 va_start (args, fmt);
505 OCTAVE_NORETURN
static
507 error_1 (octave::execution_exception&
e, std::ostream& os,
508 const char *
name,
const char *
id,
const char *fmt,
509 va_list
args,
bool with_cfn =
false)
511 bool show_stack_trace =
false;
517 size_t len =
strlen (fmt);
521 if (fmt[len - 1] ==
'\n')
526 verror (
true, os, name,
id, tmp_fmt.c_str (),
531 e.set_stack_trace ();
535 verror (
true, os, name,
id, fmt, args, with_cfn);
539 if (in_user_code && ! discard_error_messages)
540 show_stack_trace =
true;
546 panic (
"error_1: invalid format");
553 OCTAVE_NORETURN
static
556 const char *fmt, va_list
args,
bool with_cfn =
false)
560 error_1 (e, os, name,
id, fmt, args, with_cfn);
566 error_1 (std::cerr,
"error",
"", fmt, args);
573 va_start (args, fmt);
579 verror (octave::execution_exception&
e,
const char *fmt, va_list
args)
581 error_1 (e, std::cerr,
"error",
"", fmt, args);
585 error (octave::execution_exception&
e,
const char *fmt, ...)
588 va_start (args, fmt);
596 error_1 (std::cerr,
"error",
"", fmt, args,
true);
603 va_start (args, fmt);
611 error_1 (std::cerr,
"error",
id, fmt, args);
618 va_start (args, fmt);
626 error_1 (std::cerr,
"error",
id, fmt, args,
true);
633 va_start (args, fmt);
648 else if (state ==
"on")
650 else if (state ==
"error")
672 Cell identifier = warning_options.
contents (
"identifier");
675 bool all_found =
false;
676 bool id_found =
false;
683 if (! all_found && ovs ==
"all")
691 if (! id_found && ovs ==
id)
699 if (all_found && id_found)
713 else if (all_state == 1)
715 if (id_state == 0 || id_state == 2)
720 else if (all_state == 2)
740 error_1 (std::cerr,
"error",
id, fmt, args);
742 else if (warn_opt == 1)
744 bool fmt_suppresses_backtrace =
false;
745 size_t fmt_len = fmt ?
strlen (fmt) : 0;
746 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
748 if (fmt_suppresses_backtrace && fmt_len > 1)
755 vwarning (
"warning",
id, fmt, args);
759 if (! fmt_suppresses_backtrace && in_user_code
760 && Vbacktrace_on_warning
761 && ! discard_warning_messages)
764 if ((octave::application::interactive ()
765 || octave::application::forced_interactive ())
770 Vdebug_on_warning =
false;
791 va_start (args, fmt);
806 va_start (args, fmt);
814 error_1 (std::cerr, 0,
"", fmt, args);
821 va_start (args, fmt);
829 error_1 (std::cerr, 0,
id, fmt, args);
836 va_start (args, fmt);
845 va_start (args, fmt);
846 error_1 (std::cerr, 0,
id, fmt, args);
850 static std::list<error_stack_frame>
853 std::list<error_stack_frame> frames;
858 bool have_column =
false;
872 frame.
line = line(
i).int_value ();
875 frames.push_back (frame);
885 va_start (args, fmt);
886 verror (
false, std::cerr, 0,
id, fmt, args);
890 OCTAVE_NORETURN
static
900 error (
"rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
904 Vlast_error_stack = stack;
906 size_t len = msg.
length ();
909 if (len > 1 && tmp_msg[len-1] ==
'\n')
911 tmp_msg.erase (len - 1);
920 std::ostringstream buf;
924 e.set_stack_trace (buf.str ());
934 va_start (args, fmt);
935 buffer_error_messages = 0;
936 discard_error_messages =
false;
937 verror (
false, std::cerr,
"panic",
"", fmt, args);
946 va_start (args, fmt);
957 typedef void (*
error_fun)(
const char *,
const char *, ...);
998 size_t len =
strlen (msg);
1002 if (msg[len - 1] ==
'\n')
1007 f (
id,
"%s\n", tmp_msg.c_str ());
1033 if (
args.length () != 1)
1039 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1058 maybe_extract_message_id (
const std::string& caller,
1068 bool have_fmt = nargin > 1;
1079 if (arg1.find_first_of (
"% \f\n\r\t\v") == std::string::npos
1080 && arg1.find (
':') != std::string::npos
1082 && arg1[arg1.length ()-1] !=
':')
1094 nargs(0) =
"call to " + caller
1095 +
" with message identifier '" + arg1
1096 +
"' requires message";
1192 int nargin = args.
length ();
1203 bool have_fmt =
false;
1238 have_fmt = maybe_extract_message_id (
"error", args, nargs,
id);
1271 val =
state(
i).string_value ();
1283 val =
state(
i).string_value ();
1296 retval.
assign (
"identifier",
id);
1297 retval.
assign (
"state", val);
1303 default_warning_state (
void)
1316 retval =
state(
i).string_value ();
1325 display_warning_options (std::ostream& os)
1334 if (all_state ==
"on")
1335 os <<
"By default, warnings are enabled.";
1336 else if (all_state ==
"off")
1337 os <<
"By default, warnings are disabled.";
1338 else if (all_state ==
"error")
1339 os <<
"By default, warnings are treated as errors.";
1353 os << std::setw (7) << tst <<
" " << tid <<
"\n";
1364 if (state !=
"on" && state !=
"off" && state !=
"error")
1365 error (
"invalid warning state: %s", state.c_str ());
1380 if (state == all_state && ident !=
"all")
1382 for (
i =
i + 1;
i < nel;
i++)
1394 warning_options.
clear ();
1396 warning_options.
assign (
"identifier", tid);
1397 warning_options.
assign (
"state", tst);
1411 warning_options.
clear ();
1413 warning_options.
assign (
"identifier", tid);
1414 warning_options.
assign (
"state", tst);
1485 int nargin = args.
length ();
1498 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1502 if (nargin == 3 && argv[3] ==
"local"
1529 fields(0) =
"identifier";
1541 for (i = 0; i < nel; i++)
1547 states(i) = curr_state;
1561 states(nel) = curr_state;
1575 if (nargin >= 2 && arg2 ==
"all")
1580 int is_error = (arg1 ==
"error");
1582 Cell id (1, 1 + 2*is_error);
1583 Cell st (1, 1 + 2*is_error);
1595 id(1) =
"Octave:language-extension";
1598 id(2) =
"Octave:single-quote-string";
1602 tmp.
assign (
"identifier",
id);
1603 tmp.
assign (
"state", st);
1605 warning_options =
tmp;
1609 else if (arg2 ==
"backtrace")
1611 if (arg1 !=
"error")
1613 Vbacktrace_on_warning = (arg1 ==
"on");
1617 else if (arg2 ==
"debug")
1619 if (arg1 !=
"error")
1621 Vdebug_on_warning = (arg1 ==
"on");
1625 else if (arg2 ==
"verbose")
1627 if (arg1 !=
"error")
1629 Vverbose_warning = (arg1 ==
"on");
1633 else if (arg2 ==
"quiet")
1635 if (arg1 !=
"error")
1637 Vquiet_warning = (arg1 ==
"on");
1646 set_warning_option (arg1, arg2);
1652 retval = old_warning_options;
1654 else if (arg1 ==
"query")
1658 else if (arg2 ==
"backtrace" || arg2 ==
"debug"
1659 || arg2 ==
"verbose" || arg2 ==
"quiet")
1662 tmp.
assign (
"identifier", arg2);
1663 if (arg2 ==
"backtrace")
1664 tmp.
assign (
"state", Vbacktrace_on_warning ?
"on" :
"off");
1665 else if (arg2 ==
"debug")
1666 tmp.
assign (
"state", Vdebug_on_warning ?
"on" :
"off");
1667 else if (arg2 ==
"verbose")
1668 tmp.
assign (
"state", Vverbose_warning ?
"on" :
"off");
1670 tmp.
assign (
"state", Vquiet_warning ?
"on" :
"off");
1675 retval = warning_query (arg2);
1680 else if (nargin == 0)
1689 else if (nargin == 1)
1700 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1714 set_warning_option (tst, tid);
1720 retval = old_warning_options;
1730 bool have_fmt = maybe_extract_message_id (
"warning", args, nargs,
id);
1735 "unspecified warning", nargs,
1771 set_warning_option (
"off",
id);
1796 DEFUN (lasterror, args, ,
1843 int nargin = args.
length ();
1860 error (
"lasterror: unrecognized string argument");
1875 int new_error_line = -1;
1876 int new_error_column = -1;
1877 bool initialize_stack =
false;
1883 new_error_message =
tmp;
1886 if (new_err.
contains (
"identifier"))
1896 initialize_stack =
true;
1902 if (new_err_stack.
contains (
"file"))
1906 new_error_file =
tmp;
1909 if (new_err_stack.
contains (
"name"))
1913 new_error_name =
tmp;
1916 if (new_err_stack.
contains (
"line"))
1920 new_error_line =
tmp;
1923 if (new_err_stack.
contains (
"column"))
1927 new_error_column =
tmp;
1935 if (initialize_stack)
1937 else if (new_err.
contains (
"stack"))
1939 new_err_stack.
setfield (
"file", new_error_file);
1940 new_err_stack.
setfield (
"name", new_error_name);
1941 new_err_stack.
setfield (
"line", new_error_line);
1942 new_err_stack.
setfield (
"column", new_error_column);
1943 Vlast_error_stack = new_err_stack;
1955 error (
"lasterror: argument must be a structure or a string");
1990 int nargin = args.
length ();
2005 else if (nargin == 1)
2011 if (nargin == 0 ||
nargout > 0)
2012 return ovl (prev_error_message, prev_error_id);
2033 int nargin = args.
length ();
2048 else if (nargin == 1)
2054 if (nargin == 0 ||
nargout > 0)
2055 return ovl (prev_warning_message, prev_warning_id);
2062 DEFUN (__usage__, args, ,
2185 buffer_error_messages++;
2186 Vdebug_on_error =
false;
2187 Vdebug_on_warning =
false;
static bool debug_on_caught(const std::string &ID)
int warning_enabled(const std::string &id)
void panic(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
const Cell & contents(const_iterator p) const
scalar structure containing the fields
OCTAVE_EXPORT octave_value_list column
octave_idx_type nfields(void) const
std::string fcn_name(bool print_subfn=true) const
octave_map xmap_value(const char *fmt,...) const
static bool at_top_level(void)
static bool Vbeep_on_error
void vparse_error(const char *fmt, va_list args)
void assign(const std::string &k, const Cell &val)
OCTINTERP_API void initialize_default_warning_state(void)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
OCTINTERP_API size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
void verror_with_id(const char *id, const char *fmt, va_list args)
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
void rethrow_error(const char *id, const char *fmt,...)
octave_idx_type length(void) const
const octave_value & contents(const_iterator p) const
octave_map map_value(void) const
bool contains(const std::string &name) const
bool is_defined(void) const
static void vwarning(const char *name, const char *id, const char *fmt, va_list args)
bool contains(const std::string &name) const
void vmessage(const char *name, const char *fmt, va_list args)
static OCTAVE_NORETURN void error_1(octave::execution_exception &e, std::ostream &os, const char *name, const char *id, const char *fmt, va_list args, bool with_cfn=false)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
std::string name(void) const
#define SET_INTERNAL_VARIABLE(NM)
OCTINTERP_API octave_value_list set_warning_state(const std::string &id, const std::string &state)
static octave_function * current(void)
void setfield(const std::string &key, const octave_value &val)
static octave_map initialize_last_error_stack(void)
static std::string Vlast_error_message
void message_with_id(const char *name, const char *id, const char *fmt,...)
octave_idx_type numel(void) const
static bool Vverbose_warning
static OCTAVE_NORETURN void usage_1(octave::execution_exception &e, const char *id, const char *fmt, va_list args)
static bool debug_on_warn(const std::string &ID)
static std::string Vlast_warning_id
void usage(const char *fmt,...)
void usage_with_id(const char *id, const char *fmt,...)
bool is_empty(void) const
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
static octave::execution_exception make_execution_exception(const char *who)
virtual symbol_table::scope_id scope(void)
virtual bool is_map(void) const
OCTAVE_EXPORT octave_value_list search each directory of the loadpath for element of the cell array and return the first that matches If the second optional argument return a cell array containing the list of all files that have the same name in the path If no files are found
static std::string Vlast_warning_message
static bool Vquiet_warning
static std::string handle_message(error_fun f, const char *id, const char *msg, const octave_value_list &args, bool have_fmt)
static void maybe_enter_debugger(octave::execution_exception &e, bool show_stack_trace=false)
static bool Vbacktrace_on_warning
void message(const char *name, const char *fmt,...)
void verror_with_cfn(const char *fmt, va_list args)
static void pr_where(std::ostream &os, const char *who, const std::list< error_stack_frame > &frames)
int buffer_error_messages
static octave_user_code * caller_user_code(size_t nskip=0)
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
OCTINTERP_API void disable_warning(const std::string &id)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
static symbol_table::scope_id current_scope(void)
static size_t current_frame(void)
OCTINTERP_API std::string last_warning_id(void)
string_vector make_argv(const std::string &="") const
void defun_usage_message(const std::string &msg)
static octave_map Vlast_error_stack
static llvm::LLVMContext & context
std::string string_value(bool force=false) const
void error_with_cfn(const char *fmt,...)
virtual std::string string_value(bool force=false) const
void error_with_id(const char *id, const char *fmt,...)
nd deftypefn *octave_map m
static size_t current_frame
int nint_value(bool frc_str_conv=false) const
void vusage_with_id(const char *id, const char *fmt, va_list args)
bool is_string(void) const
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
void vparse_error_with_id(const char *id, const char *fmt, va_list args)
OCTINTERP_API std::string last_error_id(void)
void resize(const dim_vector &dv, const T &rfv)
static void rethrow_error_1(const char *id, const char *fmt,...)
void vmessage_with_id(const char *name, const char *id, const char *fmt, va_list args)
#define panic_impossible()
void reset_error_handler(void)
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
static void warning_1(const char *id, const char *fmt, va_list args)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
T::size_type strlen(const typename T::value_type *str)
void parse_error(const char *fmt,...)
void vusage(const char *fmt, va_list args)
static uint32_t state[624]
void warning(const char *fmt,...)
octave::unwind_protect frame
OCTINTERP_API std::string last_error_message(void)
bool is_empty(void) const
OCTINTERP_API octave_map last_error_stack(void)
static void defun_usage_message_1(const char *fmt,...)
OCTINTERP_API octave_value_list Fwarning(const octave_value_list &=octave_value_list(), int=0)
bool all_strings_p(void) const
static std::string Vlast_error_id
octave_scalar_map scalar_map_value(void) const
static octave_map warning_options
=val(i)}if ode{val(i)}occurs in table i
static 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)
virtual bool is_string(void) const
void assign(const std::string &k, const octave_value &val)
static symbol_table::context_id current_context(void)
void error_with_id_cfn(const char *id, const char *fmt,...)
void(* error_fun)(const char *, const char *,...)
static void initialize_warning_options(const std::string &state)
static std::list< octave_call_stack::stack_frame > backtrace_frames(size_t nskip=0)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_idx_type length(void) const
void parse_error_with_id(const char *id, const char *fmt,...)
bool is_empty(void) const
octave_value getfield(const std::string &key) const
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
void resize(const dim_vector &dv, bool fill=false)
static octave_map empty_backtrace(void)
OCTINTERP_API std::string last_warning_message(void)
void vwarning_with_id(const char *id, const char *fmt, va_list args)
bool discard_warning_messages
Vector representing the dimensions (size) of an Array.
bool discard_error_messages
static int check_state(const std::string &state)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
static bool debug_on_err(const std::string &ID)
static std::list< error_stack_frame > make_stack_frame_list(const octave_map &stack)
OCTINTERP_API void interpreter_try(octave::unwind_protect &)
octave_value_list Fsprintf(const octave_value_list &, int)
static octave_map backtrace(size_t nskip=0)
static void pr_where_1(std::ostream &os, const char *fmt,...)
static void pr_where_2(std::ostream &os, const char *fmt, va_list args)