changeset 29501:220c6c4a3533

leave error message output stream decision to error_system class * error.h, error.cc (error_system::display_exception): Eliminate second argument for output stream. Change all uses. Deprecate two-argument version.
author John W. Eaton <jwe@octave.org>
date Thu, 25 Mar 2021 16:25:31 -0400
parents 5fad0c81f7db
children 76fdbe78884f
files libinterp/corefcn/error.cc libinterp/corefcn/error.h libinterp/corefcn/interpreter.cc libinterp/parse-tree/pt-eval.cc
diffstat 4 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.cc	Wed Apr 07 08:04:04 2021 +0200
+++ b/libinterp/corefcn/error.cc	Thu Mar 25 16:25:31 2021 -0400
@@ -908,6 +908,7 @@
     last_error_stack (make_stack_map (ee.stack_info ()));
   }
 
+  // DEPRECATED in Octave 7.
   void error_system::display_exception (const execution_exception& ee,
                                         std::ostream& os) const
   {
@@ -917,6 +918,20 @@
     ee.display (octave_diary);
     ee.display (os);
   }
+
+  void error_system::display_exception (const execution_exception& ee) const
+  {
+    if (m_beep_on_error)
+      os << "\a";
+
+    ee.display (octave_diary);
+
+    // FIXME: Handle display using an event manager message so that the
+    // GUI or other client can receive error messages without needing to
+    // capture them from std::cerr or some other stream.
+
+    ee.display (std::cerr);
+  }
 }
 
 void
--- a/libinterp/corefcn/error.h	Wed Apr 07 08:04:04 2021 +0200
+++ b/libinterp/corefcn/error.h	Thu Mar 25 16:25:31 2021 -0400
@@ -334,8 +334,11 @@
 
     OCTINTERP_API void save_exception (const execution_exception& ee);
 
-    OCTINTERP_API void
-    display_exception (const execution_exception& ee, std::ostream& os) const;
+    OCTAVE_DEPRECATED (7, "second argument is no longer accepted")
+    OCTINTERP_API void display_exception (const execution_exception& ee,
+                                          std::ostream& os) const;
+
+    OCTINTERP_API void display_exception (const execution_exception& ee) const;
 
   private:
 
--- a/libinterp/corefcn/interpreter.cc	Wed Apr 07 08:04:04 2021 +0200
+++ b/libinterp/corefcn/interpreter.cc	Thu Mar 25 16:25:31 2021 -0400
@@ -1795,7 +1795,7 @@
     // FIXME: use a separate stream instead of std::cerr directly so that
     // error messages can be redirected more easily?  Pass the message
     // to an event manager function?
-    m_error_system.display_exception (ee, std::cerr);
+    m_error_system.display_exception (ee);
 
     recover_from_exception ();
   }
--- a/libinterp/parse-tree/pt-eval.cc	Wed Apr 07 08:04:04 2021 +0200
+++ b/libinterp/parse-tree/pt-eval.cc	Thu Mar 25 16:25:31 2021 -0400
@@ -213,7 +213,7 @@
             error_system& es = m_interpreter.get_error_system ();
 
             es.save_exception (ee);
-            es.display_exception (ee, std::cerr);
+            es.display_exception (ee);
 
             if (m_interpreter.interactive ())
               {
@@ -484,7 +484,7 @@
             catch (const execution_exception& ee)
               {
                 es.save_exception (ee);
-                es.display_exception (ee, std::cerr);
+                es.display_exception (ee);
 
                 // Ignore errors when in debugging mode;
                 m_interpreter.recover_from_exception ();
@@ -732,7 +732,7 @@
             error_system& es = m_interpreter.get_error_system ();
 
             es.save_exception (ee);
-            es.display_exception (ee, std::cerr);
+            es.display_exception (ee);
 
             if (m_interpreter.interactive ())
               m_interpreter.recover_from_exception ();
@@ -819,7 +819,7 @@
             error_system& es = m_interpreter.get_error_system ();
 
             es.save_exception (ee);
-            es.display_exception (ee, std::cerr);
+            es.display_exception (ee);
 
             if (m_interpreter.interactive ())
               {
@@ -3666,7 +3666,7 @@
                 && in_user_code ())
               {
                 es.save_exception (ee);
-                es.display_exception (ee, std::cerr);
+                es.display_exception (ee);
 
                 enter_debugger ();