OGS
ThreadException.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <exception>
7#include <mutex>
8
17{
18public:
19 void capture()
20 {
21 std::unique_lock<std::mutex> guard{lock_};
22 exception_ = std::current_exception();
23 }
24
25 void rethrow()
26 {
27 if (exception_)
28 {
29 std::rethrow_exception(exception_);
30 }
31 }
32
33 explicit operator bool() const noexcept { return exception_ != nullptr; }
34
35private:
36 std::exception_ptr exception_ = nullptr;
37 std::mutex lock_;
38};
std::exception_ptr exception_