From c25feca938e0da36c66ab53436b59c1091e8fe53 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Mon, 27 May 2019 16:46:53 +0200 Subject: [PATCH] startup() may throw RuntimeError --- Adapter.hh | 2 +- Adapter.hxx | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Adapter.hh b/Adapter.hh index 745a457..907f8f1 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -29,7 +29,7 @@ namespace pEp { T *obj = nullptr, std::function< void (T *) > _startup = nullptr, std::function< void (T *) > _shutdown = nullptr - ); + ) throw (RuntimeError); // returns 'true' when called from the "sync" thread, 'false' otherwise. bool on_sync_thread(); diff --git a/Adapter.hxx b/Adapter.hxx index fb6e51c..8e783da 100644 --- a/Adapter.hxx +++ b/Adapter.hxx @@ -47,6 +47,7 @@ namespace pEp { function< void(T *) > _startup, function< void(T *) > _shutdown ) + throw (RuntimeError) { if (messageToSend) _messageToSend = messageToSend; @@ -59,8 +60,15 @@ namespace pEp { { std::lock_guard lock(m); - if (!_sync_thread) - _sync_thread = new std::thread(sync_thread, obj, _startup, _shutdown); + if (!_sync_thread) { + try { + _sync_thread = new std::thread(sync_thread, obj, _startup, _shutdown); + } + catch (RuntimeError& ex) { + _sync_thread = nullptr; + throw ex; + } + } } } }