summaryrefslogtreecommitdiff
path: root/salhelper
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-12-03 09:29:56 +0100
committerStephan Bergmann <sbergman@redhat.com>2021-12-03 11:00:03 +0100
commit0c1c300ed7ce168755ae945822eb7a1c610cfa25 (patch)
treec090b924d97765bbef812b36e9ae084b94419f94 /salhelper
parent7f02cb80ac2075b65ee1adee4e29d1d5c4819424 (diff)
Rather use ScopeGuard to prevent catch and rethrow
...than 6bc5d6cac2fd9e029357c618510a3b5f3aa7c085 "remove counter-productive catch-all blocks" Change-Id: I07fe5821ef5bf60f74f5ceb5feedd7dc79e73dfa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126275 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'salhelper')
-rw-r--r--salhelper/source/thread.cxx15
1 files changed, 8 insertions, 7 deletions
diff --git a/salhelper/source/thread.cxx b/salhelper/source/thread.cxx
index 190daf5081b6..66713a2a3f10 100644
--- a/salhelper/source/thread.cxx
+++ b/salhelper/source/thread.cxx
@@ -12,6 +12,7 @@
#include <stdexcept>
#include <string>
+#include <comphelper/scopeguard.hxx>
#include <sal/log.hxx>
#include <salhelper/thread.hxx>
@@ -22,21 +23,21 @@ void salhelper::Thread::launch() {
// Assumption is that osl::Thread::create returns normally with a true
// return value iff it causes osl::Thread::run to start executing:
acquire();
- try {
- if (!create()) {
- throw std::runtime_error("osl::Thread::create failed");
- }
- } catch (...) {
- release();
- throw;
+ comphelper::ScopeGuard g([this] { release(); });
+ if (!create()) {
+ throw std::runtime_error("osl::Thread::create failed");
}
+ g.dismiss();
}
salhelper::Thread::~Thread() {}
void salhelper::Thread::run() {
+ // Work around the problem that onTerminated is not called if run throws an exception:
+ comphelper::ScopeGuard g([this] { onTerminated(); });
setName(name_);
execute();
+ g.dismiss();
}
void salhelper::Thread::onTerminated() { release(); }