aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-11-10 19:51:58 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-11-11 17:38:38 +0000
commit83594fbc6dba4893701b5b30397bdbaedd36f6d7 (patch)
tree116fd5121920eebb22a0d0c190931109292866e9
parentac97c0471e05d07efdb673bbef5665470bc4925a (diff)
downloadpaludis-83594fbc6dba4893701b5b30397bdbaedd36f6d7.tar.gz
paludis-83594fbc6dba4893701b5b30397bdbaedd36f6d7.tar.xz
Catch exceptions in threads
-rw-r--r--paludis/util/thread.cc12
-rw-r--r--paludis/util/thread.hh2
2 files changed, 13 insertions, 1 deletions
diff --git a/paludis/util/thread.cc b/paludis/util/thread.cc
index d6b9247..3a5e69f 100644
--- a/paludis/util/thread.cc
+++ b/paludis/util/thread.cc
@@ -49,7 +49,14 @@ Thread::Thread(const std::tr1::function<void () throw ()> & f) :
void *
Thread::thread_func(void * r)
{
- static_cast<Thread *>(r)->_func();
+ try
+ {
+ static_cast<Thread *>(r)->_func();
+ }
+ catch (const std::exception & e)
+ {
+ static_cast<Thread *>(r)->_exception = e.what();
+ }
return 0;
}
@@ -57,6 +64,9 @@ Thread::~Thread()
{
pthread_join(*_thread, 0);
delete _thread;
+
+ if (! _exception.empty())
+ throw InternalError(PALUDIS_HERE, "Exception '" + _exception + "' uncaught in child thread");
}
void
diff --git a/paludis/util/thread.hh b/paludis/util/thread.hh
index dd8a616..126d9cc 100644
--- a/paludis/util/thread.hh
+++ b/paludis/util/thread.hh
@@ -22,6 +22,7 @@
#include <paludis/util/attributes.hh>
#include <tr1/functional>
+#include <string>
#ifdef PALUDIS_ENABLE_THREADS
# include <pthread.h>
@@ -55,6 +56,7 @@ namespace paludis
#ifdef PALUDIS_ENABLE_THREADS
pthread_t * const _thread;
const std::tr1::function<void () throw ()> _func;
+ std::string _exception;
static void * thread_func(void *);
#endif