Skip to main content

throws_ Struct Template

Operator struct template to check if an expression throws a specific exception. More...

Declaration

template <class Callable_T, class Exception_T = void>
struct micro_os_plus::micro_test_plus::detail::throws_<Callable_T, Exception_T> { ... }

Included Headers

Base struct

structcallable_op_

Common base struct for callable-wrapping operators. More...

Public Constructors Index

template <class Callable_T, class Exception_T = void>
constexprthrows_ (const Callable_T &func)

Constructs an exception checking operator for the given callable. More...

Public Operators Index

template <class Callable_T, class Exception_T = void>
constexproperator bool () const

Conversion operator to boolean. More...

Private Member Attributes Index

template <class Callable_T, class Exception_T = void>
const boolvalue_ {}

Stores the result of the callable invocation. More...

Description

Operator struct template to check if an expression throws a specific exception.

This specialisation checks whether invoking the given callable throws an exception of the specified type. The check is performed at construction time, with the result cached for reporting and composition. Use this when a test must verify that an operation raises an expected exception of a particular type.

Template Parameters
Callable_T

The type of the callable object to be invoked.

Exception_T

The type of the exception to check for (defaults to void for any exception).

Definition at line 653 of file detail.h.

Public Constructors

throws_()

template <class Callable_T, class Exception_T = void>
micro_os_plus::micro_test_plus::detail::throws_< Callable_T, Exception_T >::throws_ (const Callable_T & func)
explicit constexpr

Constructs an exception checking operator for the given callable.

Parameters
func

The callable object to be invoked.

Invokes func inside a try/catch block. If func throws an exception of type Exception_T, the result is true; if it throws any other exception the result is false; if no exception is thrown the result is false. The result is passed to the callable_op_ base class constructor.

Declaration at line 661 of file detail.h, definition at line 571 of file detail-inlines.h.

572 const Callable_T& func)
573 : callable_op_{ [&func]
574 {
575 try
576 {
577 func ();
578 }
579 catch (const Exception_T&)
580 {
581 return true;
582 }
583 catch (...)
584 {
585 return false;
586 }
587 return false;
588 }() }
589 {
590 }

Reference micro_os_plus::micro_test_plus::detail::callable_op_::callable_op_.

Referenced by micro_os_plus::micro_test_plus::detail::throws_< Callable_T, void >::throws_.

Public Operators

operator bool()

template <class Callable_T, class Exception_T = void>
micro_os_plus::micro_test_plus::detail::callable_op_::operator bool ()
nodiscard constexpr

Conversion operator to boolean.

Parameters

None.

Returns

The result of the callable invocation.

Returns the pre-computed boolean result stored by the derived operator's constructor.

Declaration at line 624 of file detail.h, definition at line 555 of file detail-inlines.h.

555 operator bool () const
556 {
557 return value_;
558 }

Reference micro_os_plus::micro_test_plus::detail::callable_op_::value_.

Private Member Attributes

value_

template <class Callable_T, class Exception_T = void>
const bool micro_os_plus::micro_test_plus::detail::callable_op_::value_ {}

Stores the result of the callable invocation.

Definition at line 630 of file detail.h.

630 const bool value_{};

Referenced by micro_os_plus::micro_test_plus::detail::callable_op_::callable_op_ and micro_os_plus::micro_test_plus::detail::callable_op_::operator bool.


The documentation for this struct was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.