[gnote] Use exception_ptr for saving and rethrowing exception



commit eba67e12075d9f172af615acc2afe76651b39695
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Nov 13 17:49:34 2019 +0200

    Use exception_ptr for saving and rethrowing exception

 src/synchronization/syncdialog.cpp | 14 ++++++--------
 src/synchronization/syncdialog.hpp |  2 +-
 2 files changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 79a23ae8..ce51bc3b 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -598,7 +598,7 @@ void SyncDialog::note_conflict_detected(const Note::Ptr & localConflictNote,
 {
   int dlgBehaviorPref = m_gnote.preferences()
     .get_schema_settings(Preferences::SCHEMA_SYNC)->get_int(Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR);
-  std::exception *mainThreadException = NULL;
+  std::exception_ptr mainThreadException;
 
   // This event handler will be called by the synchronization thread
   // so we have to use the delegate here to manipulate the GUI.
@@ -608,14 +608,12 @@ void SyncDialog::note_conflict_detected(const Note::Ptr & localConflictNote,
     [this, localConflictNote, remoteNote, noteUpdateTitles, dlgBehaviorPref, &mainThreadException]() {
       note_conflict_detected_(localConflictNote, remoteNote, noteUpdateTitles,
                               static_cast<SyncTitleConflictResolution>(dlgBehaviorPref),
-                              OVERWRITE_EXISTING, &mainThreadException
+                              OVERWRITE_EXISTING, mainThreadException
       );
     });
 
   if(mainThreadException) {
-    std::exception e(*mainThreadException);
-    delete mainThreadException;
-    throw e;
+    throw mainThreadException;
   }
 }
 
@@ -626,7 +624,7 @@ void SyncDialog::note_conflict_detected_(
   const std::vector<Glib::ustring> & noteUpdateTitles,
   SyncTitleConflictResolution savedBehavior,
   SyncTitleConflictResolution resolution,
-  std::exception **mainThreadException)
+  std::exception_ptr & mainThreadException)
 {
   try {
     SyncTitleConflictDialog conflictDlg(localConflictNote, noteUpdateTitles);
@@ -691,8 +689,8 @@ void SyncDialog::note_conflict_detected_(
     // Let the SyncManager continue
     m_gnote.sync_manager().resolve_conflict(/*localConflictNote, */resolution);
   }
-  catch(std::exception & e) {
-    *mainThreadException = new std::exception(e);
+  catch(std::exception &) {
+    mainThreadException = std::current_exception();
   }
 }
 
diff --git a/src/synchronization/syncdialog.hpp b/src/synchronization/syncdialog.hpp
index ff787f06..ad0ee1d3 100644
--- a/src/synchronization/syncdialog.hpp
+++ b/src/synchronization/syncdialog.hpp
@@ -64,7 +64,7 @@ namespace sync {
                                  const std::vector<Glib::ustring> & noteUpdateTitles,
                                  SyncTitleConflictResolution savedBehavior,
                                  SyncTitleConflictResolution resolution,
-                                 std::exception **mainThreadException);
+                                 std::exception_ptr & mainThreadException);
 
     bool on_pulse_progress_bar();
     void on_row_activated(const Gtk::TreeModel::Path & path, Gtk::TreeViewColumn *column);


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