std::contract_violation

< cpp‎ | error
 
 
 
Error handling
Exception handling
Exception handling failures
(until C++17)
(until C++17)
(C++11)(until C++17)
(until C++17)
Contracts
contract_violation
(C++20)
 
Defined in header <contract>
class contract_violation;
(since C++20)

The class contract_violation describes information about a contract violation. It is generated by a C++ implementation and passed to a contract violation handler when a contract violation is detected.

Member functions

line_number
returns the line number where the contract violation happened
(public member function)
file_name
returns the name of the file where the contract violation happened
(public member function)
function_name
returns the name of the function where the contract violation happened
(public member function)
comment
returns a string describing the predicate of the violated contract
(public member function)
assertion_level
returns a string describing the assertion level of the violated contract
(public member function)

std::contract_violation::line_number

std::uint_least32_t line_number() const noexcept;

Returns the location of the source code where the contract violation happened. If the name is unknown, an implementation may return 0 instead.

std::contract_violation::file_name

std::string_view file_name() const noexcept;

Returns the name of the the source file where the contract violation happened. If the name is unknown, an implementation may return an empty string_view instead.

std::contract_violation::function_name

std::string_view function_name() const noexcept;

Returns the name of the function where the contract violation happened. If the name is unknown, an implementation may return an empty string_view instead.

std::contract_violation::comment

std::string_view comment() const noexcept;

Returns an implementation-defined string describing the predicate of the violated contract.

std::contract_violation::assertion_level

std::string_view assertion_level() const noexcept;

Returns a string describing the assertion level of the violated contract.