AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::ut::ThreadErrors Class Reference

Exceptions raised in threads started by a unit test. More...

#include <threadErrors.hpp>

Collaboration diagram for anch::ut::ThreadErrors:

Public Member Functions

 ThreadErrors ()=default
 ThreadErrors (const ThreadErrors &)=delete
 ThreadErrors (ThreadErrors &&)=delete
template<typename F>
auto wrap (F &&func)
void capture () noexcept
bool failed ()
void rethrow ()

Detailed Description

Exceptions raised in threads started by a unit test.

An exception (as a failed assertion) raised in a thread other than the test one can not be caught by the runner: the process is terminated (std::terminate ) without any report.
Wrap thread functions with wrap : the first exception raised in a wrapped function is kept, and it is raised again in the test thread by rethrow once threads have been joined.

std::thread thread(errors.wrap([]() {
anch::ut::assertThat(check(), "check failed in thread");
}));
thread.join();
errors.rethrow(); // the failed assertion is reported by the runner
Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ ThreadErrors() [1/3]

anch::ut::ThreadErrors::ThreadErrors ( )
default

ThreadErrors default constructor

◆ ThreadErrors() [2/3]

anch::ut::ThreadErrors::ThreadErrors ( const ThreadErrors & )
delete

Forbids ThreadErrors copy constructor (wrapped functions keep a reference on it)

Here is the call graph for this function:

◆ ThreadErrors() [3/3]

anch::ut::ThreadErrors::ThreadErrors ( ThreadErrors && )
delete

Forbids ThreadErrors move constructor (wrapped functions keep a reference on it)

Here is the call graph for this function:

Member Function Documentation

◆ capture()

void anch::ut::ThreadErrors::capture ( )
noexcept

Keep the exception which is currently handled (when there is no previous one).
It has to be called in a catch block.

◆ failed()

bool anch::ut::ThreadErrors::failed ( )

Check if an exception has been raised

Returns
true when an exception has been kept, false otherwise
Here is the call graph for this function:

◆ rethrow()

void anch::ut::ThreadErrors::rethrow ( )

Raise the first exception which has been kept (do nothing when there is none)

Exceptions
thekept exception
Here is the call graph for this function:

◆ wrap()

template<typename F>
auto anch::ut::ThreadErrors::wrap ( F && func)

Wrap function to keep the exception it raises. This object has to outlive the returned function.

Template Parameters
Fthe function type
Parameters
functhe function to wrap
Returns
the wrapped function (which takes the same arguments and returns nothing)

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