OGS
ThreadException Class Reference

Detailed Description

Initial code from https://stackoverflow.com/questions/11828539/elegant-exception-handling-in-openmp

The implementation does not guarantee, that while the exception is being checked for nullptr in the bool-conversion operator, the capture is not changing the pointer. This might lead to an exception being lost if there are two exceptions thrown simultaneously.

Definition at line 22 of file ThreadException.h.

#include <ThreadException.h>

Public Member Functions

void capture ()
 
void rethrow ()
 
 operator bool () const noexcept
 

Private Attributes

std::exception_ptr exception_ = nullptr
 
std::mutex lock_
 

Member Function Documentation

◆ capture()

void ThreadException::capture ( )
inline

Definition at line 25 of file ThreadException.h.

26 {
27 std::unique_lock<std::mutex> guard{lock_};
28 exception_ = std::current_exception();
29 }
std::exception_ptr exception_

References exception_, and lock_.

Referenced by anonymous_namespace{ParallelVectorMatrixAssembler.cpp}::runAssembly().

◆ operator bool()

ThreadException::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 39 of file ThreadException.h.

39{ return exception_ != nullptr; }

References exception_.

◆ rethrow()

void ThreadException::rethrow ( )
inline

Definition at line 31 of file ThreadException.h.

32 {
33 if (exception_)
34 {
35 std::rethrow_exception(exception_);
36 }
37 }

References exception_.

Referenced by ProcessLib::Assembly::ParallelVectorMatrixAssembler::assembleWithJacobian().

Member Data Documentation

◆ exception_

std::exception_ptr ThreadException::exception_ = nullptr
private

Definition at line 42 of file ThreadException.h.

Referenced by capture(), operator bool(), and rethrow().

◆ lock_

std::mutex ThreadException::lock_
private

Definition at line 43 of file ThreadException.h.

Referenced by capture().


The documentation for this class was generated from the following file: