The Checking Exceptions Reference
Functions for verifying exceptions in test cases. More...
Functions Index
constexpr auto | nothrow (const Callable_T &func) |
Check if a callable does not throw an exception. More... | |
constexpr auto | throws (const Callable_T &func) |
Check if a callable throws a specific exception. More... | |
constexpr auto | throws (const Callable_T &func) |
Check if a callable throws an exception (any exception). More... | |
Description
Functions for verifying exceptions in test cases.
The µTest++ framework provides dedicated functions for verifying whether specific expressions or function calls throw exceptions, supporting robust testing of error handling and exceptional conditions in C++ code.
These utilities enable developers to assert that exceptions are correctly thrown or not thrown as expected, improving the reliability and safety of software components. The framework supports both generic exception checks and type-specific exception verification, allowing for precise and expressive test cases.
For more advanced scenarios, such as handling multiple expected exceptions, developers can use explicit try
blocks with multiple catch
statements and report the results using expect(true)
or expect(false)
. This approach ensures comprehensive coverage of exception handling logic.
- Examples
If more advanced logic is required, such as handling multiple expected exceptions, use an explicit try
block with several catch
statements, and report the outcomes using expect(true)
or expect(false)
.
Functions
nothrow()
| nodiscardconstexpr |
Check if a callable does not throw an exception.
- Template Parameters
Callable_T The type of the callable object to be invoked.
- Parameters
[in] func The callable object to check for exception safety.
- Returns
An output stream to write optional messages.
The nothrow
function template verifies whether invoking the provided callable object does not result in the throwing of any exception within the µTest++ framework. This is useful for testing exception safety and ensuring that code under test does not unexpectedly signal error conditions.
The function returns an output stream, allowing optional messages to be appended to the test report for diagnostic purposes.
Definition at line 242 of file micro-test-plus-inlines.h.
throws()
| nodiscardconstexpr |
Check if a callable throws a specific exception.
- Template Parameters
Exception_T The type of the exception expected to be thrown. Callable_T The type of the callable object to be invoked.
- Parameters
[in] func The callable object to check for exception throwing behaviour.
- Returns
An output stream to write optional messages.
The throws
function template verifies whether invoking the provided callable object results in the throwing of a specific exception type within the µTest++ framework. This is useful for testing error handling and exception safety in code under test.
The function returns an output stream, allowing optional messages to be appended to the test report for diagnostic purposes.
Definition at line 207 of file micro-test-plus-inlines.h.
throws()
| nodiscardconstexpr |
Check if a callable throws an exception (any exception).
- Template Parameters
Callable_T The type of the callable object to be invoked.
- Parameters
[in] func The callable object to check for exception throwing behaviour.
- Returns
An output stream to write optional messages.
The throws
function template verifies whether invoking the provided callable object results in the throwing of any exception within the µTest++ framework. This is useful for testing general exception safety and ensuring that code under test properly signals error conditions.
The function returns an output stream, allowing optional messages to be appended to the test report for diagnostic purposes.
Definition at line 224 of file micro-test-plus-inlines.h.
Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.