changeset 28000:768b54395b31

also derive exit_exception and interrupt_exception from std::exception * quit.h (class exit_exception): Derive from std::exception. Use default function definitions where possible. (class interrupt_exception): Likewise. (exit_exception::what, interrupt_exception::what): New methods.
author John W. Eaton <jwe@octave.org>
date Fri, 24 Jan 2020 15:12:47 -0500
parents 9d4711b6cd43
children 3c6a91ee72c2
files liboctave/util/quit.h
diffstat 1 files changed, 19 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/util/quit.h	Fri Jan 24 08:51:54 2020 -0500
+++ b/liboctave/util/quit.h	Fri Jan 24 15:12:47 2020 -0500
@@ -158,33 +158,23 @@
     stack_info_type m_stack_info;
   };
 
-  // Intentionally not derived from std::exception.
-
-  class exit_exception
+  class exit_exception : public std::exception
   {
   public:
 
     exit_exception (int exit_status = 0, bool safe_to_return = false)
-      : m_exit_status (exit_status), m_safe_to_return (safe_to_return)
-    { }
-
-    exit_exception (const exit_exception& ex)
-      : m_exit_status (ex.m_exit_status), m_safe_to_return (ex.m_safe_to_return)
+      : std::exception (), m_exit_status (exit_status),
+        m_safe_to_return (safe_to_return)
     { }
 
-    exit_exception& operator = (exit_exception& ex)
-    {
-      if (this != &ex)
-        {
-          m_exit_status = ex.m_exit_status;
-          m_safe_to_return = ex.m_safe_to_return;
-        }
+    exit_exception (const exit_exception&) = default;
 
-      return *this;
-    }
+    exit_exception& operator = (exit_exception&) = default;
 
     ~exit_exception (void) = default;
 
+    const char * what (void) const noexcept { return "exit exception"; }
+
     int exit_status (void) const { return m_exit_status; }
 
     bool safe_to_return (void) const { return m_safe_to_return; }
@@ -196,10 +186,19 @@
     bool m_safe_to_return;
   };
 
-  // Intentionally not derived from std::exception.
+  class interrupt_exception : public std::exception
+  {
+  public:
+
+    interrupt_exception (void) = default;
 
-  class interrupt_exception
-  {
+    interrupt_exception (const interrupt_exception&) = default;
+
+    interrupt_exception& operator = (const interrupt_exception&) = default;
+
+    ~interrupt_exception (void) = default;
+
+    const char * what (void) const noexcept { return "interrupt exception"; }
   };
 }