Mercurial > octave
changeset 27997:e90e3155cd01
derive execution_exception from std::exception
* quit.h (class execution_exception): Derive from std::exception.
(execution_exception::what): New method.
* lo-array-errwarn.h, lo-array-errwarn.cc (index_exception::what):
New method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 Jan 2020 16:22:27 -0500 |
parents | 1998edbd4490 |
children | 9d4711b6cd43 |
files | liboctave/util/lo-array-errwarn.cc liboctave/util/lo-array-errwarn.h liboctave/util/quit.h |
diffstat | 3 files changed, 25 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/lo-array-errwarn.cc Thu Jan 23 16:19:33 2020 -0500 +++ b/liboctave/util/lo-array-errwarn.cc Thu Jan 23 16:22:27 2020 -0500 @@ -128,6 +128,13 @@ return expression () + ": " + details (); } + const char * index_exception::what (void) const noexcept + { + std::string tmp = message (); + + return tmp.c_str (); + } + // Show the expression that caused the error, e.g., "A(-1,_)", // "A(0+1i)", "A(_,3)". Show how many indices come before/after the // offending one, e.g., (<error>), (<error>,_), or (_,<error>,...[x5]...)
--- a/liboctave/util/lo-array-errwarn.h Thu Jan 23 16:19:33 2020 -0500 +++ b/liboctave/util/lo-array-errwarn.h Thu Jan 23 16:22:27 2020 -0500 @@ -52,8 +52,8 @@ ~index_exception (void) = default; - // Erroneous index value. Called in what, and by external code - // (e.g., nth_element) to make a custom error message. + // Erroneous index value. Called in message method and by external + // code (e.g., nth_element) to make a custom error message. std::string idx (void) const { return m_index; } // details set by subclass. @@ -64,6 +64,9 @@ virtual std::string message (void) const; + // Provided for std::exception interface. + const char * what (void) const noexcept; + // Position of error: dimension in error, and number of dimensions. void set_pos (octave_idx_type nd_arg, octave_idx_type dim_arg) {
--- a/liboctave/util/quit.h Thu Jan 23 16:19:33 2020 -0500 +++ b/liboctave/util/quit.h Thu Jan 23 16:22:27 2020 -0500 @@ -33,6 +33,7 @@ # include <csignal> # include <iosfwd> # include <list> +# include <stdexcept> # include <string> extern "C" { #else @@ -88,8 +89,7 @@ && a.column () == b.column ()); } - class - execution_exception + class execution_exception : std::runtime_error { public: @@ -99,8 +99,8 @@ const std::string& id = "", const std::string& message = "unspecified error", const stack_info_type& stack_info = stack_info_type ()) - : m_err_type (err_type), m_id (id), m_message (message), - m_stack_info (stack_info) + : runtime_error (message), m_err_type (err_type), m_id (id), + m_message (message), m_stack_info (stack_info) { } execution_exception (const execution_exception&) = default; @@ -132,6 +132,9 @@ virtual std::string message (void) const { return m_message; } + // Provided for std::exception interface. + const char * what (void) const noexcept { return m_message.c_str (); } + virtual stack_info_type stack_info (void) const { return m_stack_info; @@ -155,8 +158,9 @@ stack_info_type m_stack_info; }; - class - exit_exception + // Intentionally not derived from std::exception. + + class exit_exception { public: @@ -192,8 +196,9 @@ bool m_safe_to_return; }; - class - interrupt_exception + // Intentionally not derived from std::exception. + + class interrupt_exception { }; }