Exceptions raised in threads started by a unit test.
More...
#include <threadErrors.hpp>
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();
- Author
- Vincent Lachenal
- Since
- 0.2
◆ ThreadErrors() [1/3]
| anch::ut::ThreadErrors::ThreadErrors |
( |
| ) |
|
|
default |
◆ ThreadErrors() [2/3]
| anch::ut::ThreadErrors::ThreadErrors |
( |
const ThreadErrors & | | ) |
|
|
delete |
Forbids ThreadErrors copy constructor (wrapped functions keep a reference on it)
◆ ThreadErrors() [3/3]
| anch::ut::ThreadErrors::ThreadErrors |
( |
ThreadErrors && | | ) |
|
|
delete |
Forbids ThreadErrors move constructor (wrapped functions keep a reference on it)
◆ 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
◆ rethrow()
| void anch::ut::ThreadErrors::rethrow |
( |
| ) |
|
Raise the first exception which has been kept (do nothing when there is none)
- Exceptions
-
◆ 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
-
- Parameters
-
- Returns
- the wrapped function (which takes the same arguments and returns nothing)
The documentation for this class was generated from the following file: