[gnote] Handle exceptions in GTK+ level signal handlers



commit c3372cd60f2433f923a7e92f2d8813f36bed8bc1
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sat Feb 4 18:45:07 2012 +0200

    Handle exceptions in GTK+ level signal handlers

 src/synchronization/syncdialog.cpp  |   14 ++++++-
 src/synchronization/syncmanager.cpp |   66 ++++++++++++++++++++++------------
 2 files changed, 55 insertions(+), 25 deletions(-)
---
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index bf87809..2fcfe25 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -518,7 +518,12 @@ void SyncDialog::sync_state_changed(SyncState state)
 
 void SyncDialog::on_sync_state_changed(GObject*, int state, gpointer data)
 {
-  static_cast<SyncDialog*>(data)->sync_state_changed_(static_cast<SyncState>(state));
+  try {
+    static_cast<SyncDialog*>(data)->sync_state_changed_(static_cast<SyncState>(state));
+  }
+  catch(...) {
+    DBG_OUT("Exception caught in %s\n", __func__);
+  }
 }
 
 
@@ -622,7 +627,12 @@ void SyncDialog::note_synchronized(const std::string & noteTitle, NoteSyncType t
 
 void SyncDialog::on_note_synchronized(GObject*, const char * noteTitle, int type, gpointer data)
 {
-  static_cast<SyncDialog*>(data)->note_synchronized_(noteTitle, static_cast<NoteSyncType>(type));
+  try {
+    static_cast<SyncDialog*>(data)->note_synchronized_(noteTitle, static_cast<NoteSyncType>(type));
+  }
+  catch(...) {
+    DBG_OUT("Exception caught in %s\n", __func__);
+  }
 }
 
 
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 387021e..df339d9 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -773,46 +773,66 @@ namespace sync {
 
   void SyncManager::on_delete_notes(GObject*, gpointer serv, gpointer)
   {
-    SyncServer::Ptr & server = *static_cast<SyncServer::Ptr*>(serv);
-    // Make list of all local notes
-    std::list<Note::Ptr> localNotes = SyncManager::obj().note_mgr().get_notes();
-
-    // Get all notes currently on server
-    std::list<std::string> serverNotes = server->get_all_note_uuids();
-
-    // Delete notes locally that have been deleted on the server
-    for(std::list<Note::Ptr>::iterator iter = localNotes.begin(); iter != localNotes.end(); ++iter) {
-      if(SyncManager::obj().m_client->get_revision(*iter) != -1
-         && std::find(serverNotes.begin(), serverNotes.end(), (*iter)->id()) == serverNotes.end()) {
-        if(SyncManager::obj().m_sync_ui != 0) {
-          SyncManager::obj().m_sync_ui->note_synchronized((*iter)->get_title(), DELETE_FROM_CLIENT);
-        }
-        SyncManager::obj().note_mgr().delete_note(*iter);
+    try {
+      SyncServer::Ptr & server = *static_cast<SyncServer::Ptr*>(serv);
+      // Make list of all local notes
+      std::list<Note::Ptr> localNotes = SyncManager::obj().note_mgr().get_notes();
+
+      // Get all notes currently on server
+      std::list<std::string> serverNotes = server->get_all_note_uuids();
+
+      // Delete notes locally that have been deleted on the server
+      for(std::list<Note::Ptr>::iterator iter = localNotes.begin(); iter != localNotes.end(); ++iter) {
+	if(SyncManager::obj().m_client->get_revision(*iter) != -1
+	   && std::find(serverNotes.begin(), serverNotes.end(), (*iter)->id()) == serverNotes.end()) {
+	  if(SyncManager::obj().m_sync_ui != 0) {
+	    SyncManager::obj().m_sync_ui->note_synchronized((*iter)->get_title(), DELETE_FROM_CLIENT);
+	  }
+	  SyncManager::obj().note_mgr().delete_note(*iter);
+	}
       }
     }
+    catch(...) {
+      DBG_OUT("Exception caught in %s\n", __func__);
+    }
   }
 
 
   void SyncManager::on_create_note(GObject*, gpointer note_update, gpointer)
   {
-    NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
-    Note::Ptr existingNote = SyncManager::obj().note_mgr().create_with_guid(noteUpdate.m_title, noteUpdate.m_uuid);
-    SyncManager::obj().update_local_note(existingNote, noteUpdate, DOWNLOAD_NEW);
+    try {
+      NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
+      Note::Ptr existingNote = SyncManager::obj().note_mgr().create_with_guid(noteUpdate.m_title, noteUpdate.m_uuid);
+      SyncManager::obj().update_local_note(existingNote, noteUpdate, DOWNLOAD_NEW);
+    }
+    catch(...) {
+      DBG_OUT("Exception caught in %s\n", __func__);
+    }
   }
 
 
   void SyncManager::on_update_note(GObject*, gpointer existing_note, gpointer note_update, gpointer)
   {
-    Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
-    NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
-    SyncManager::obj().update_local_note(*existingNote, noteUpdate, DOWNLOAD_MODIFIED);
+    try {
+      Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
+      NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
+      SyncManager::obj().update_local_note(*existingNote, noteUpdate, DOWNLOAD_MODIFIED);
+    }
+    catch(...) {
+      DBG_OUT("Exception caught in %s\n", __func__);
+    }
   }
 
 
   void SyncManager::on_delete_note(GObject*, gpointer existing_note, gpointer)
   {
-    Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
-    SyncManager::obj().note_mgr().delete_note(*existingNote);
+    try {
+      Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
+      SyncManager::obj().note_mgr().delete_note(*existingNote);
+    }
+    catch(...) {
+      DBG_OUT("Exception caught in %s\n", __func__);
+    }
   }
 
 



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