diff libinterp/octave-value/ov-complex.cc @ 28012:9a965fec21c1

refactor index_exception classes to accommodate std::exception::what method Since the std::exception::what method returns a pointer to a character buffer, make sure that we will return a pointer that is valid at least until the next non-const method is called for the exception object. * quit.h (execution_exception::message): No longer virtual. * lo-array-errwarn.h, lo-array-errwarn.cc (index_exception::message, index_exception::what, index_exception::idx, index_exception::details): Delete. (index_exception::update_message): New virtual method. Call it in constructors and non-const methods. (invalid_index::details, out_of_range::details): Delete. (invalid_index::update_message, out_of_range::update_message): New functions. * data.cc (index_error): Delete static function. Change all uses to call error directly and to use index_exception::what instead of idx and details. * sub2ind.cc (Find2sub): Use use index_exception::what instead of idx and details. Update test. * utils.cc (dims_to_numel): Use use index_exception::what instead of idx and details. * ov-base-mat.cc (octave_base_matrix<MT>::assign): Consistent with other functions in the same file, use index_exception::set_pos_if_unset and rethrow exception instead of calling err_invalid_index. * ov-complex.cc (complex_index_exception::details): Delete. (complex_index_exception::update_message): New function.
author John W. Eaton <jwe@octave.org>
date Sun, 26 Jan 2020 23:07:45 -0500
parents bd51beb6205e
children 4c21f99b4ad5 0a5b15007766
line wrap: on
line diff
--- a/libinterp/octave-value/ov-complex.cc	Sun Jan 26 23:16:24 2020 -0500
+++ b/libinterp/octave-value/ov-complex.cc	Sun Jan 26 23:07:45 2020 -0500
@@ -74,13 +74,18 @@
   public:
 
     complex_index_exception (const std::string& value)
-      : index_exception (value) { }
+      : index_exception (value)
+    {
+      // Virtual, but the one we want to call is defined in this class.
+      update_message ();
+    }
 
     ~complex_index_exception (void) = default;
 
-    std::string details (void) const
+    void update_message (void)
     {
-      return "subscripts must be real (forgot to initialize i or j?)";
+      set_message (expression ()
+                   + ": subscripts must be real (forgot to initialize i or j?)");
     }
 
     // ID of error to throw.