[nemiver] Do not throw in destructors



commit 6c3c522d686ed34ddb4c59573621a066afce98e6
Author: Dodji Seketeli <dodji seketeli org>
Date:   Wed Nov 2 15:12:57 2016 +0100

    Do not throw in destructors
    
    This patch fixes code that throws exceptions in some destructors because
    by default, c++11 destructors don't throw so G++ emits a warning about
    this now.  The patch thus replaces the throwing by an explicit call to abort().
    
        * src/common/nmv-exception.h: Update copyright notice.
        (ABORT_IF_FAIL2): New macro that takes to parameters.
        (ABORT_IF_FAIL): Make this macro take just one parameter.
        * src/common/nmv-log-stream.cc: Update copyright notice.
        (TransactionAutoHelper::~TransactionAutoHelper): Use the new
        ABORT_IF_FAIL2 macro, rather throwing an exception.
        * src/persp/dbgperspective/nmv-preferences-dialog.cc
        (PreferencesDialog::~PreferencesDialog): Likewise.
    
    Signed-off-by: Dodji Seketeli <dodji seketeli org>

 src/common/nmv-exception.h                         |   34 +++++++++++++-------
 src/common/nmv-log-stream.cc                       |   22 ++++++------
 src/common/nmv-transaction.h                       |    3 +-
 src/persp/dbgperspective/nmv-preferences-dialog.cc |    2 +-
 4 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/src/common/nmv-exception.h b/src/common/nmv-exception.h
index 49fdc45..649fae5 100644
--- a/src/common/nmv-exception.h
+++ b/src/common/nmv-exception.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset: 4-*- */
 
-/*Copyright (c) 2005-2006 Dodji Seketeli
+/*Copyright (c) 2005-2016 Dodji Seketeli
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this
- * software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit
- * persons to whom the Software is furnished to do so,
- * subject to the following conditions:
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all copies
- * or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS",
  * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
@@ -81,11 +81,21 @@ LOG_EXCEPTION ("condition (" << #a_cond << ") failed; raising exception " << #ty
 << ":  " << a_reason << "\n" ); _THROW (type (a_reason))  ;\
 }
 
-#define ABORT_IF_FAIL(a_cond, a_reason) \
+#define ABORT_IF_FAIL(a_cond) \
 if (!(a_cond)) { \
-LOG_EXCEPTION ("condition (" << #a_cond << ") failed; raising exception " << a_reason <<"\n"); abort();\
+LOG_EXCEPTION ("condition (" << #a_cond << ") failed; aborting");\
 }
 
+#define ABORT_IF_FAIL2(a_cond, a_reason) \
+if (!(a_cond)) { \
+LOG_EXCEPTION ("condition (" << #a_cond << ") failed; aborting because " << a_reason <<"\n"); abort();\
+}
+
+#define ABORT(a_reason) \
+do { \
+ LOG_EXCEPTION("aborting because: #a_reason"); abort(); \
+ } while (false)
+
 #define THROW(a_reason) \
 LOG_EXCEPTION ("raised exception: "<< (nemiver::common::UString (a_reason)) << "\n"); \
 _THROW (nemiver::common::Exception (nemiver::common::UString (a_reason))) ;
diff --git a/src/common/nmv-log-stream.cc b/src/common/nmv-log-stream.cc
index 6822de1..dee70ba 100644
--- a/src/common/nmv-log-stream.cc
+++ b/src/common/nmv-log-stream.cc
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset: 4-*- */
 
-/*Copyright (c) 2005-2006 Dodji Seketeli
+/*Copyright (c) 2005-2016 Dodji Seketeli
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this
- * software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit
- * persons to whom the Software is furnished to do so,
- * subject to the following conditions:
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all copies
- * or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS",
  * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
@@ -396,7 +396,7 @@ LogStream::LogStream (enum LogLevel a_level,
 LogStream::~LogStream ()
 {
     LOG_D ("delete", "destructor-domain");
-    if (!m_priv) throw runtime_error ("double free in LogStrea::~LogStream");
+    ABORT_IF_FAIL2 (!m_priv, "double free in LogStream::~LogStream");
     m_priv.reset ();
 }
 
diff --git a/src/common/nmv-transaction.h b/src/common/nmv-transaction.h
index 5c30331..008ea94 100644
--- a/src/common/nmv-transaction.h
+++ b/src/common/nmv-transaction.h
@@ -122,7 +122,8 @@ struct TransactionAutoHelper
             return;
         }
         if (m_is_started) {
-            THROW_IF_FAIL (m_trans.rollback ());
+            ABORT_IF_FAIL2 (m_trans.rollback (),
+                           "Failed to rollback transation");
             m_is_started = false;
         }
     }
diff --git a/src/persp/dbgperspective/nmv-preferences-dialog.cc 
b/src/persp/dbgperspective/nmv-preferences-dialog.cc
index 611cbfd..e133d16 100644
--- a/src/persp/dbgperspective/nmv-preferences-dialog.cc
+++ b/src/persp/dbgperspective/nmv-preferences-dialog.cc
@@ -943,7 +943,7 @@ PreferencesDialog::PreferencesDialog (Gtk::Window &a_parent,
 PreferencesDialog::~PreferencesDialog ()
 {
     LOG_D ("delete", "destructor-domain");
-    THROW_IF_FAIL (m_priv);
+    ABORT_IF_FAIL (m_priv);
 }
 
 const std::vector<UString>&


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]