...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::contract::assertion_failure — Exception typically used to report a contract assertion failure.
// In header: <boost/contract/core/exception.hpp> class assertion_failure : public std::exception, public boost::contract::exception { public: // construct/copy/destruct explicit assertion_failure(char const * = "", unsigned long = 0, char const * = ""); explicit assertion_failure(char const *); ~assertion_failure(); // public member functions virtual char const * what() const; char const * file() const; unsigned long line() const; char const * code() const; };
This exception is thrown by code expanded by BOOST_CONTRACT_ASSERT
(but it can also be thrown by user code programmed manually without that macro). This exception is typically used to report contract assertion failures because it contains detailed information about the file name, line number, and source code of the asserted condition (so it can be used by this library to provide detailed error messages). However, any other exception can be used to report a contract assertion failure (including user-defined exceptions).
This library will call the appropriate contract failure handler function ( boost::contract::precondition_failure
, etc.) when this or any other exception is thrown while checking contracts (by default, these failure handler functions print an error message to std::cerr
and terminate the program, but they can be customized to take any other action).
See Also:
assertion_failure
public
construct/copy/destructexplicit assertion_failure(char const * file = "", unsigned long line = 0, char const * code = "");Construct this object with file name, line number, and source code text of an assertion condition (all optional).
This constructor can also be used to specify no information (default constructor), or to specify only file name and line number but not source code text (because of the parameter default values).
Parameters: |
|
explicit assertion_failure(char const * code);Construct this object only with the source code text of the assertion condition.
Parameters: |
|
~assertion_failure();Destruct this object.
Throws: This is declared noexcept
(or throw()
before C++11).
assertion_failure
public member functionsvirtual char const * what() const;String describing the failed assertion.
Throws: This is declared noexcept
(or throw()
before C++11).
Returns: |
A string formatted similarly to the following: |
char const * file() const;Name of the file containing the assertion.
Returns: |
File name as specified at construction (or |
unsigned long line() const;Number of the line containing the assertion.
Returns: |
Line number as specified at construction (or |
char const * code() const;Text listing the source code of the assertion condition.
Returns: |
Assertion condition source code as specified at construction (or |