diff libinterp/corefcn/call-stack.h @ 27471:fd32c1a9b1bd

revamp error handling In "error" and similar functions that ultimately call it, simply throw an exception that contains information about the error (message, id, stack info) instead of printing an error message immediately and then throwing an exception. The new approach is more flexible and sllows for some simplification of the error message routines as they no longer need feedback from the interpreter to know when to display or buffer messages. It is now the responsibility of any code that catches an execution exception to determine whether and when to display error messages. * quit.h, quit.cc (class frame_info): New class. (execution_exception::m_err_type, execution_exception::m_id, execution_exception::m_message, execution_exception::m_stack_info): New data members. (class execution_exception): Store error type, message, id, and stack info. Provide methods setting and accessing data as needed and for generating stack trace message from stack info. (execution_exception::m_stack_trace): Delete data member. execution_exception::set_stack_trace): Delete method. (execution_exception::set_err_type, execution_exception::err_type, execution_exception::stack_trace, execution_exception::set_identifier, execution_exception::identifier, execution_exception::message, execution_exception::set_stack_info, execution_exception::display): New methods. * call-stack.cc, call-stack.h (call_stack::backtrace_info): New functions. * oct-parse.yy (maybe_print_last_error_message): Delete function and all uses. * pt-eval.h, pt-eval.cc (tree_evaluator::backtrace_info, tree_evaluator::backtrace_message): New functions. (tree_evaluator::backtrace): Now const. (tree_evaluator::visit_unwind_protect_command, tree_evaluator::do_unwind_protect_cleanup_code, tree_evaluator::visit_try_catch_command, tree_evaluator::evalin, tree_evaluator::eval, tree_evaluator::repl, debugger::repl): Save current exception info. * interpreter.h, interpreter.cc (interpreter::handle_exception): New function. Use it in place of direct calls to error_system::save_exception, error_system::display_exception (or execution_exception::display) and interpreter::recover_from_exception, so that we have uniform behavior when responding to an execution exception. * error.h, error.cc (error_system::m_buffer_error_messages, error_system::m_discard_error_messages, error_system::m_in_try_catch): Delete data members and associated functions. Remove all uses. Because the error system no longer displays messages immediately, it does not need to track whether to discard or buffer error messages or know whether error and warning functions are invoked inside of try-catch blocks. Everywhere that catches execution_exceptions must now handle saving the exception state (for lasterror) and displaying the error message and traceback as needed. (): Delete functions and all uses. (error_stack_frame): Delete struct definition. (verror, vpr_where, pr_where_internal, pr_where, maybe_enter_debugger, make_execution_exception, vmessage_with_id, message_with_id, error_system::maybe_enter_debugger, reset_error_handler, error_system::reset): Delete functions and all uses. (error_system::try_option): Delete enum and all uses. (vusage, error_1, error_system::vwarning, error_system::rethrow_error, error_system::interpreter_try): Simplify. (format_message, make_stack_map, error_system::throw_error, error_system::save_exception, error_system::display_exception): New functions. (Ferror): Update for error_system changes.
author John W. Eaton <jwe@octave.org>
date Fri, 04 Oct 2019 01:15:13 -0400
parents 8408acb7ca4f
children e091e09d26f0
line wrap: on
line diff
--- a/libinterp/corefcn/call-stack.h	Fri Oct 04 00:30:34 2019 -0400
+++ b/libinterp/corefcn/call-stack.h	Fri Oct 04 01:15:13 2019 -0400
@@ -35,6 +35,8 @@
 class octave_value;
 class octave_value_list;
 
+#include "quit.h"
+
 #include "stack-frame.h"
 #include "symscope.h"
 
@@ -227,8 +229,21 @@
     std::list<stack_frame *>
     backtrace_frames (octave_idx_type& curr_user_frame) const;
 
+    // List of raw stack frames.
+
     std::list<stack_frame *> backtrace_frames (void) const;
 
+    // List of stack_info objects that can be used in liboctave and
+    // stored in the execution_exception object.
+
+    std::list<frame_info> backtrace_info (octave_idx_type& curr_user_frame,
+                                          bool print_subfn = true) const;
+
+    std::list<frame_info> backtrace_info (void) const;
+
+    // The same as backtrace_info but in the form of a struct array
+    // object that may be used in the interpreter.
+
     octave_map backtrace (octave_idx_type& curr_user_frame,
                           bool print_subfn = true) const;