Exceptions

The cvc5 API communicates certain errors using exceptions. We broadly distinguish two types of exceptions: CVC5ApiException and CVC5ApiRecoverableException (which is derived from CVC5ApiException).

If any method fails with a CVC5ApiRecoverableException, the solver behaves as if the failing method was not called. The solver can still be used safely.

If, however, a method fails with a CVC5ApiException, the associated object may be in an unsafe state and it should no longer be used.

If the cvc5::parser::InputParser encounters an error, it will throw a cvc5::parser::ParserException. If thrown, API objects can still be used

class CVC5ApiException : public exception

Base class for all API exceptions. If thrown, all API objects may be in an unsafe state.

Subclassed by cvc5::CVC5ApiRecoverableException, cvc5::parser::ParserException

Public Functions

inline CVC5ApiException(const std::string &str)

Construct with message from a string.

Parameters:

str – The error message.

inline CVC5ApiException(const std::stringstream &stream)

Construct with message from a string stream.

Parameters:

stream – The error message.

inline const std::string &getMessage() const

Retrieve the message from this exception.

Returns:

The error message.

inline const char *what() const noexcept override

Retrieve the message as a C-style array.

Returns:

The error message.

inline virtual void toStream(std::ostream &os) const

Printing: feel free to redefine toStream(). When overridden in a derived class, it’s recommended that this method print the type of exception before the actual message.

class CVC5ApiRecoverableException : public cvc5::CVC5ApiException

A recoverable API exception. If thrown, API objects can still be used.

Subclassed by cvc5::CVC5ApiOptionException, cvc5::CVC5ApiUnsupportedException

Public Functions

inline CVC5ApiRecoverableException(const std::string &str)

Construct with message from a string.

Parameters:

str – The error message.

inline CVC5ApiRecoverableException(const std::stringstream &stream)

Construct with message from a string stream.

Parameters:

stream – The error message.

class ParserException : public cvc5::CVC5ApiException

Base class for all Parser exceptions. If thrown, API objects can still be used

Subclassed by cvc5::parser::ParserEndOfFileException

Public Functions

ParserException()

Default constructor

ParserException(const std::string &msg)

Construct with message from a string.

Parameters:

msg – The error message.

ParserException(const char *msg)

Construct with message from a C string.

Parameters:

msg – The error message.

ParserException(const std::string &msg, const std::string &filename, unsigned long line, unsigned long column)

Construct with message from a string.

Parameters:
  • msg – The error message.

  • filename – name of the file.

  • line – The error line number.

  • column – The error column number.

virtual void toStream(std::ostream &os) const override

Print error to output stream.

Parameters:

os – The output stream to write the error on.

std::string getFilename() const
Returns:

The file name.

unsigned long getLine() const
Returns:

The line number of the parsing error.

unsigned long getColumn() const
Returns:

The column number of the parsing error.