23 #if defined (HAVE_CONFIG_H) 37 #include "builtin-defun-decls.h" 137 initw.
setfield (
"identifier",
"all");
154 const char *
name,
const char *
id,
const char *fmt, va_list args,
155 bool with_cfn =
false)
167 std::ostringstream output_buf;
177 if (to_beep_or_not_to_beep_p)
183 msg_string +=
"caught error: ";
203 if (cfn.length () > base_msg.length ()
204 || base_msg.compare (0, cfn.length (), cfn) != 0)
206 msg_string += cfn +
' ';
212 msg_string += base_msg +
'\n';
247 size_t len =
strlen (fmt);
251 if (fmt[len - 1] ==
'\n')
256 verror (
false,
os,
nullptr,
"", tmp_fmt.c_str (), args);
260 verror (
false,
os,
nullptr,
"", fmt, args);
265 panic (
"pr_where_2: invalid format");
272 va_start (args, fmt);
287 const std::list<error_stack_frame>& frames)
289 size_t nframes = frames.size ();
294 for (
const auto& frm : frames)
318 std::list<octave::call_stack::stack_frame> call_stack_frames
323 call_stack_frames.unique ();
325 std::list<error_stack_frame> frames;
326 for (
const auto& frm : call_stack_frames)
330 frame.name = frm.fcn_name ();
331 frame.line = frm.line ();
332 frame.column = frm.column ();
334 frames.push_back (
frame);
340 octave::execution_exception
343 std::ostringstream buf;
347 octave::execution_exception
retval;
349 retval.set_stack_trace (buf.str ());
356 bool show_stack_trace =
false)
361 if ((octave::application::interactive ()
362 || octave::application::forced_interactive ())
375 if (show_stack_trace)
379 if (! stack_trace.empty ())
381 std::cerr << stack_trace;
383 e.set_stack_trace ();
394 vwarning (
const char *
name,
const char *
id,
const char *fmt, va_list args)
401 std::ostringstream output_buf;
415 msg_string += base_msg +
'\n';
424 std::cerr << msg_string;
431 verror (
false, std::cerr,
name,
"", fmt, args);
438 va_start (args, fmt);
447 verror (
false, std::cerr,
name,
id, fmt, args);
454 va_start (args, fmt);
459 OCTAVE_NORETURN
static 461 usage_1 (octave::execution_exception&
e,
const char *
id,
462 const char *fmt, va_list args)
464 verror (
true, std::cerr,
"usage",
id, fmt, args);
471 OCTAVE_NORETURN
static 473 usage_1 (
const char *
id,
const char *fmt, va_list args)
490 va_start (args, fmt);
505 va_start (args, fmt);
510 OCTAVE_NORETURN
static 513 const char *
name,
const char *
id,
const char *fmt,
514 va_list args,
bool with_cfn =
false)
516 bool show_stack_trace =
false;
522 size_t len =
strlen (fmt);
526 if (fmt[len - 1] ==
'\n')
536 e.set_stack_trace ();
548 show_stack_trace =
true;
554 panic (
"error_1: invalid format");
561 OCTAVE_NORETURN
static 564 const char *fmt, va_list args,
bool with_cfn =
false)
574 error_1 (std::cerr,
"error",
"", fmt, args);
581 va_start (args, fmt);
587 verror (octave::execution_exception&
e,
const char *fmt, va_list args)
589 error_1 (
e, std::cerr,
"error",
"", fmt, args);
593 error (octave::execution_exception&
e,
const char *fmt, ...)
596 va_start (args, fmt);
604 error_1 (std::cerr,
"error",
"", fmt, args,
true);
611 va_start (args, fmt);
619 error_1 (std::cerr,
"error",
id, fmt, args);
626 va_start (args, fmt);
634 error_1 (std::cerr,
"error",
id, fmt, args,
true);
641 va_start (args, fmt);
656 else if (
state ==
"on")
658 else if (
state ==
"error")
683 bool all_found =
false;
684 bool id_found =
false;
691 if (! all_found && ovs ==
"all")
699 if (! id_found && ovs ==
id)
707 if (all_found && id_found)
721 else if (all_state == 1)
723 if (id_state == 0 || id_state == 2)
728 else if (all_state == 2)
740 warning_1 (
const char *
id,
const char *fmt, va_list args)
748 error_1 (std::cerr,
"error",
id, fmt, args);
750 else if (warn_opt == 1)
752 bool fmt_suppresses_backtrace =
false;
753 size_t fmt_len = (fmt ?
strlen (fmt) : 0);
754 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] ==
'\n');
756 if (fmt_suppresses_backtrace && fmt_len > 1)
760 vwarning (
"warning",
id, tmp_fmt.c_str (), args);
763 vwarning (
"warning",
id, fmt, args);
769 if (! fmt_suppresses_backtrace && in_user_code
777 if ((octave::application::interactive ()
778 || octave::application::forced_interactive ())
804 va_start (args, fmt);
819 va_start (args, fmt);
827 error_1 (std::cerr,
nullptr,
"", fmt, args);
834 va_start (args, fmt);
842 error_1 (std::cerr,
nullptr,
id, fmt, args);
849 va_start (args, fmt);
858 va_start (args, fmt);
859 error_1 (std::cerr,
nullptr,
id, fmt, args);
863 static std::list<error_stack_frame>
866 std::list<error_stack_frame> frames;
871 bool have_column =
false;
886 frame.column = (have_column ?
column(
i).int_value () : -1);
888 frames.push_back (
frame);
898 va_start (args, fmt);
899 verror (
false, std::cerr,
nullptr,
id, fmt, args);
903 OCTAVE_NORETURN
static 913 error (
"rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
919 size_t len = msg.
length ();
922 if (len > 1 && tmp_msg[len-1] ==
'\n')
924 tmp_msg.erase (len - 1);
933 std::ostringstream buf;
937 e.set_stack_trace (buf.str ());
947 va_start (args, fmt);
950 verror (
false, std::cerr,
"panic",
"", fmt, args);
959 va_start (args, fmt);
970 typedef void (*
error_fun)(
const char *,
const char *, ...);
1011 size_t len =
strlen (msg);
1015 if (msg[len - 1] ==
'\n')
1020 f (
id,
"%s\n", tmp_msg.c_str ());
1034 DEFUN (rethrow, args, ,
1046 if (args.length () != 1)
1051 if (! (
err.contains (
"message") &&
err.contains (
"identifier")))
1052 error (
"rethrow: ERR struct must contain the fields 'message' and 'identifier'");
1059 if (
err.contains (
"stack"))
1060 err_stack =
err.contents (
"stack").xmap_value (
"ERR.STACK must be a struct");
1071 maybe_extract_message_id (
const std::string& caller,
1081 bool have_fmt =
nargin > 1;
1091 if (arg1.find_first_of (
"% \f\n\r\t\v") == std::string::npos
1092 && arg1.find (
':') != std::string::npos
1094 && arg1.back () !=
':')
1103 nargs(
i-1) = args(
i);
1106 nargs(0) =
"call to " + caller
1107 +
" with message identifier '" + arg1
1108 +
"' requires message";
1215 bool have_fmt =
false;
1220 if (args(0).isempty ())
1234 nargs(0) =
c.string_value ();
1242 id =
c.string_value ();
1250 have_fmt = maybe_extract_message_id (
"error", args, nargs,
id);
1281 if (ident(
i).string_value () ==
id)
1293 if (ident(
i).string_value () ==
"all")
1315 default_warning_state (
void)
1326 if (ident(
i).string_value () ==
"all")
1337 display_warning_options (std::ostream&
os)
1346 if (all_state ==
"on")
1347 os <<
"By default, warnings are enabled.";
1348 else if (all_state ==
"off")
1349 os <<
"By default, warnings are disabled.";
1350 else if (all_state ==
"error")
1351 os <<
"By default, warnings are treated as errors.";
1365 os << std::setw (7) << tst <<
" " << tid <<
"\n";
1377 error (
"invalid warning state: %s",
state.c_str ());
1386 if (tid(
i).string_value () == ident)
1392 if (
state == all_state && ident !=
"all")
1394 for (
i =
i + 1;
i < nel;
i++)
1560 if (arg1 ==
"on" || arg1 ==
"off" || arg1 ==
"error")
1567 old_warning_options =
octave_map (warning_query (arg2));
1584 = scope.
varval (
".saved_warning_states.");
1594 fields(0) =
"identifier";
1606 for (
i = 0;
i < nel;
i++)
1612 states(
i) = curr_state;
1626 states(nel) = curr_state;
1639 if (
nargin >= 2 && arg2 ==
"all")
1644 int is_error = (arg1 ==
"error");
1646 Cell id (1, 1 + 2*is_error);
1647 Cell st (1, 1 + 2*is_error);
1659 id(1) =
"Octave:language-extension";
1662 id(2) =
"Octave:single-quote-string";
1666 tmp.assign (
"identifier",
id);
1667 tmp.assign (
"state", st);
1673 else if (arg2 ==
"backtrace")
1675 if (arg1 !=
"error")
1681 else if (arg2 ==
"debug")
1683 if (arg1 !=
"error")
1689 else if (arg2 ==
"verbose")
1691 if (arg1 !=
"error")
1697 else if (arg2 ==
"quiet")
1699 if (arg1 !=
"error")
1710 set_warning_option (arg1, arg2);
1716 retval = old_warning_options;
1718 else if (arg1 ==
"query")
1722 else if (arg2 ==
"backtrace" || arg2 ==
"debug" 1723 || arg2 ==
"verbose" || arg2 ==
"quiet")
1726 tmp.assign (
"identifier", arg2);
1727 if (arg2 ==
"backtrace")
1729 else if (arg2 ==
"debug")
1731 else if (arg2 ==
"verbose")
1739 retval = warning_query (arg2);
1764 error (
"warning: STATE structure must have fields 'identifier' and 'state'");
1780 oldstate(
i) = warning_query (tid).getfield (
"state");
1782 old_warning_options.
setfield (
"state", oldstate);
1790 set_warning_option (tst, tid);
1796 retval = old_warning_options;
1806 bool have_fmt = maybe_extract_message_id (
"warning", args, nargs,
id);
1811 "unspecified warning", nargs,
1851 return Fwarning (interp, args, 1);
1860 return Fwarning (interp, args, 1);
1866 set_warning_option (
"off",
id);
1952 if (args(0).is_string ())
1954 if (args(0).string_value () !=
"reset")
1955 error (
"lasterror: unrecognized string argument");
1970 int new_error_line = -1;
1971 int new_error_column = -1;
1972 bool initialize_stack =
false;
1978 new_error_message =
tmp;
1981 if (new_err.
contains (
"identifier"))
1991 initialize_stack =
true;
1997 if (new_err_stack.
contains (
"file"))
2001 new_error_file =
tmp;
2004 if (new_err_stack.
contains (
"name"))
2008 new_error_name =
tmp;
2011 if (new_err_stack.
contains (
"line"))
2015 new_error_line =
tmp;
2018 if (new_err_stack.
contains (
"column"))
2022 new_error_column =
tmp;
2030 if (initialize_stack)
2032 else if (new_err.
contains (
"stack"))
2034 new_err_stack.
setfield (
"file", new_error_file);
2035 new_err_stack.
setfield (
"name", new_error_name);
2036 new_err_stack.
setfield (
"line", new_error_line);
2037 new_err_stack.
setfield (
"column", new_error_column);
2051 error (
"lasterror: argument must be a structure or a string");
2108 return ovl (prev_error_message, prev_error_id);
2151 return ovl (prev_warning_message, prev_warning_id);
int warning_enabled(const std::string &id)
void panic(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode isstruct
scalar structure containing the fields
OCTAVE_EXPORT octave_value_list column
is already an absolute the name is checked against the file system instead of Octave s loadpath In this if otherwise an empty string is returned If the first argument is a cell array of 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
bool contains(const std::string &name) const
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
interpreter & __get_interpreter__(const std::string &who)
static bool Vbeep_on_error
std::string string_value(bool force=false) const
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_map map_value(void) const
bool debug_on_warn(const std::string &id)
OCTINTERP_API void print_usage(void)
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 const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
void rethrow_error(const char *id, const char *fmt,...)
int nint_value(bool frc_str_conv=false) const
static void vwarning(const char *name, const char *id, const char *fmt, va_list args)
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)
octave_map backtrace(size_t nskip, octave_idx_type &curr_user_frame, bool print_subfn=true) const
octave_map empty_backtrace(void) const
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
#define SET_INTERNAL_VARIABLE(NM)
OCTINTERP_API octave_value_list set_warning_state(const std::string &id, const std::string &state)
octave_user_code * caller_user_code(size_t nskip=0) const
void setfield(const std::string &key, const octave_value &val)
bool is_defined(void) const
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,...)
static bool Vverbose_warning
static OCTAVE_NORETURN void usage_1(octave::execution_exception &e, const char *id, const char *fmt, va_list args)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
static std::string Vlast_warning_id
void usage(const char *fmt,...)
void usage_with_id(const char *id, const char *fmt,...)
void(* error_fun)(const char *, const char *,...)
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,...)
bool contains(const std::string &name) const
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
nd deftypefn *std::string name
octave_value & assign(assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
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)
OCTINTERP_API std::string last_warning_id(void)
void defun_usage_message(const std::string &msg)
static octave_map Vlast_error_stack
void error_with_cfn(const char *fmt,...)
void error_with_id(const char *id, const char *fmt,...)
static size_t current_frame
void vusage_with_id(const char *id, const char *fmt, va_list args)
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)
string_vector make_argv(const std::string &="") const
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
bool debug_on_err(const std::string &id)
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()
bool debug_on_caught(const std::string &id)
void reset_error_handler(void)
const Cell & contents(const_iterator p) const
symbol_scope require_current_scope(const std::string &who)
static void warning_1(const char *id, const char *fmt, va_list args)
octave_value getfield(const std::string &key) const
bool isstruct(void) const
T::size_type strlen(const typename T::value_type *str)
void parse_error(const char *fmt,...)
octave_idx_type numel(void) const
octave_value varval(const std::string &name) const
void vusage(const char *fmt, va_list args)
static uint32_t state[624]
void setfield(const std::string &key, const Cell &val)
octave_function * current(void) const
void warning(const char *fmt,...)
octave::unwind_protect frame
OCTINTERP_API std::string last_error_message(void)
octave_scalar_map scalar_map_value(void) const
OCTINTERP_API octave_map last_error_stack(void)
static void defun_usage_message_1(const char *fmt,...)
static std::string Vlast_error_id
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
octave::execution_exception make_execution_exception(const char *who)
static octave_map warning_options
bp_table & __get_bp_table__(const std::string &who)
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)
std::list< call_stack::stack_frame > backtrace_frames(size_t nskip, octave_idx_type &curr_user_frame) const
void force_assign(const std::string &name, const octave_value &value)
void error_with_id_cfn(const char *id, const char *fmt,...)
call_stack & __get_call_stack__(const std::string &who)
octave_idx_type length(void) const
static void initialize_warning_options(const std::string &state)
bool all_strings_p(void) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
void parse_error_with_id(const char *id, const char *fmt,...)
bool is_string(void) const
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
void resize(const dim_vector &dv, bool fill=false)
OCTINTERP_API std::string last_warning_message(void)
void vwarning_with_id(const char *id, const char *fmt, va_list args)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
octave_idx_type nfields(void) const
bool discard_warning_messages
Vector representing the dimensions (size) of an Array.
bool discard_error_messages
std::string name(void) const
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 std::list< error_stack_frame > make_stack_frame_list(const octave_map &stack)
size_t current_frame(void) const
line(const graphics_handle &mh, const graphics_handle &p)
OCTINTERP_API void interpreter_try(octave::unwind_protect &)
octave_value_list Fsprintf(const octave_value_list &, int)
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)