kaycxx-assert
C++ assertion library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
kaycxx::assert::assertion_error Class Reference

Thrown when an assertion fails. More...

#include <kaycxx/assert/assertion_error.hpp>

Inheritance diagram for kaycxx::assert::assertion_error:
Inheritance graph
[legend]
Collaboration diagram for kaycxx::assert::assertion_error:
Collaboration graph
[legend]

Public Member Functions

 assertion_error (std::string const &message, std::string_view reason, std::string actual, std::string expected, std::optional< std::source_location > location=std::nullopt)
 Creates an assertion error with already-rendered diagnostic values.
 
std::string constreason () const noexcept
 Returns the optional assertion reason.
 
std::string constactual () const noexcept
 Returns the rendered actual value.
 
std::string constexpected () const noexcept
 Returns the rendered expected value.
 
std::optional< std::source_location > constlocation () const noexcept
 Returns the source location of the failed assertion.
 

Detailed Description

Thrown when an assertion fails.

Constructor & Destructor Documentation

◆ assertion_error()

kaycxx::assert::assertion_error::assertion_error ( std::string const message,
std::string_view  reason,
std::string  actual,
std::string  expected,
std::optional< std::source_location >  location = std::nullopt 
)
explicit

Creates an assertion error with already-rendered diagnostic values.

The reason is appended to the exception message when present and is also stored separately. Actual and expected values are stored as rendered strings so the exception type stays non-template and easy to catch.

Parameters
messageAssertion message without the optional reason suffix.
reasonOptional assertion reason.
actualRendered actual value.
expectedRendered expected value.
locationOptional source location of the failed assertion.

Member Function Documentation

◆ actual()

std::string const & kaycxx::assert::assertion_error::actual ( ) const
noexcept

Returns the rendered actual value.

Returns
Rendered actual value.

◆ expected()

std::string const & kaycxx::assert::assertion_error::expected ( ) const
noexcept

Returns the rendered expected value.

Returns
Rendered expected value.

◆ location()

std::optional< std::source_location > const & kaycxx::assert::assertion_error::location ( ) const
noexcept

Returns the source location of the failed assertion.

Returns
Optional source location of the failed assertion.

◆ reason()

std::string const & kaycxx::assert::assertion_error::reason ( ) const
noexcept

Returns the optional assertion reason.

Returns
Optional assertion reason, or an empty string when no reason was provided.

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