kaycxx-assert
C++ assertion library
Loading...
Searching...
No Matches
assertion_error.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
11#include <optional>
12#include <source_location>
13#include <stdexcept>
14#include <string>
15#include <string_view>
16
17namespace kaycxx::assert {
18
22class assertion_error : public std::logic_error {
23public:
37 std::string const& message,
38 std::string_view reason,
39 std::string actual,
40 std::string expected,
41 std::optional<std::source_location> location = std::nullopt
42 );
43
49 std::string const& reason() const noexcept;
50
56 std::string const& actual() const noexcept;
57
63 std::string const& expected() const noexcept;
64
70 std::optional<std::source_location> const& location() const noexcept;
71
72private:
73 std::string reason_;
74 std::string actual_;
75 std::string expected_;
76 std::optional<std::source_location> location_;
77};
78
79} // namespace kaycxx::assert
Thrown when an assertion fails.
Definition assertion_error.hpp:22
std::string const & expected() const noexcept
Returns the rendered expected value.
std::string const & actual() const noexcept
Returns the rendered actual value.
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::optional< std::source_location > const & location() const noexcept
Returns the source location of the failed assertion.
std::string const & reason() const noexcept
Returns the optional assertion reason.
Assertion functions and related types.
Definition assert.hpp:15