From 2848b093a1764d00ee9f2c0b92c1b50f38c62d71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Mon, 28 Mar 2011 19:56:30 +0200
Subject: Catch all exceptions in event loop.


diff --git a/Swiften/EventLoop/EventLoop.cpp b/Swiften/EventLoop/EventLoop.cpp
index 69d8abe..56bb6ac 100644
--- a/Swiften/EventLoop/EventLoop.cpp
+++ b/Swiften/EventLoop/EventLoop.cpp
@@ -12,8 +12,18 @@
 
 #include <Swiften/Base/Log.h>
 
+
 namespace Swift {
 
+inline void invokeCallback(const Event& event) {
+	try {
+		event.callback();
+	}
+	catch (const std::exception& e) {
+		std::cerr << "Uncaught exception in event loop: " << e.what() << std::endl;
+	}
+}
+
 EventLoop::EventLoop() : nextEventID_(0), handlingEvents_(false) {
 }
 
@@ -41,24 +51,14 @@ void EventLoop::handleEvent(const Event& event) {
 	}
 	if (doCallback) {
 		handlingEvents_ = true;
-		try {
-			event.callback();
-		}
-		catch (const boost::bad_function_call&) {
-			SWIFT_LOG(error) << "Invalid function call" << std::endl;
-		}
+		invokeCallback(event);
 
 		// Process events that were passed to handleEvent during the callback
 		// (i.e. through recursive calls of handleEvent)
 		while (!eventsToHandle_.empty()) {
 			Event nextEvent = eventsToHandle_.front();
 			eventsToHandle_.pop_front();
-			try {
-				nextEvent.callback();
-			}
-			catch (const boost::bad_function_call&) {
-				SWIFT_LOG(error) << "Invalid function call" << std::endl;
-			}
+			invokeCallback(nextEvent);
 		}
 		handlingEvents_ = false;
 	}
-- 
cgit v0.10.2-6-g49f6