https://gitlab.opengeosys.org/ogs/ogs.git
Raw File
Tip revision: fa9ad3a5289541d1346184308d11513e9dbc2058 authored by Dmitry Yu. Naumov on 02 October 2023, 22:02:50 UTC
Merge branch 'FixConstructMeshesFromGeometryBulkElementIds' into 'master'
Tip revision: fa9ad3a
ThreadException.h
/**
 * \file
 * \copyright
 * Copyright (c) 2012-2023, OpenGeoSys Community (http://www.opengeosys.org)
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/project/license
 */

#pragma once

#include <exception>
#include <mutex>

/// Initial code from
/// https://stackoverflow.com/questions/11828539/elegant-exception-handling-in-openmp
class ThreadException
{
public:
    void capture()
    {
        std::unique_lock<std::mutex> guard{lock_};
        exception_ = std::current_exception();
    }

    void rethrow()
    {
        if (exception_)
        {
            std::rethrow_exception(exception_);
        }
    }

private:
    std::exception_ptr exception_ = nullptr;
    std::mutex lock_;
};
back to top