std::stringstream d_stream;
};
+class CVC5ApiUnsupportedExceptionStream
+{
+ public:
+ CVC5ApiUnsupportedExceptionStream() {}
+ /* Note: This needs to be explicitly set to 'noexcept(false)' since it is
+ * a destructor that throws an exception and in C++11 all destructors
+ * default to noexcept(true) (else this triggers a call to std::terminate). */
+ ~CVC5ApiUnsupportedExceptionStream() noexcept(false)
+ {
+ if (std::uncaught_exceptions() == 0)
+ {
+ throw CVC5ApiUnsupportedException(d_stream.str());
+ }
+ }
+
+ std::ostream& ostream() { return d_stream; }
+
+ private:
+ std::stringstream d_stream;
+};
+
#define CVC5_API_TRY_CATCH_BEGIN \
try \
{
std::string Solver::getInfo(const std::string& flag) const
{
CVC5_API_TRY_CATCH_BEGIN;
- CVC5_API_RECOVERABLE_CHECK(d_slv->isValidGetInfoFlag(flag))
- << "Unrecognized flag for getInfo.";
+ CVC5_API_UNSUPPORTED_CHECK(d_slv->isValidGetInfoFlag(flag))
+ << "Unrecognized flag: " << flag << ".";
//////// all checks before this line
return d_slv->getInfo(flag);
////////
std::string Solver::getOption(const std::string& option) const
{
- CVC5_API_TRY_CATCH_BEGIN;
- //////// all checks before this line
- return d_slv->getOption(option);
- ////////
- CVC5_API_TRY_CATCH_END;
+ try
+ {
+ return d_slv->getOption(option);
+ }
+ catch (OptionException& e)
+ {
+ throw CVC5ApiUnsupportedException(e.getMessage());
+ }
}
// Supports a visitor from a list of lambdas
void Solver::setInfo(const std::string& keyword, const std::string& value) const
{
CVC5_API_TRY_CATCH_BEGIN;
- CVC5_API_RECOVERABLE_ARG_CHECK_EXPECTED(
+ CVC5_API_UNSUPPORTED_CHECK(
keyword == "source" || keyword == "category" || keyword == "difficulty"
- || keyword == "filename" || keyword == "license" || keyword == "name"
- || keyword == "notes" || keyword == "smt-lib-version"
- || keyword == "status",
- keyword)
- << "'source', 'category', 'difficulty', 'filename', 'license', 'name', "
+ || keyword == "filename" || keyword == "license" || keyword == "name"
+ || keyword == "notes" || keyword == "smt-lib-version"
+ || keyword == "status")
+ << "Unrecognized keyword: " << keyword
+ << ", expected 'source', 'category', 'difficulty', "
+ "'filename', 'license', 'name', "
"'notes', 'smt-lib-version' or 'status'";
CVC5_API_RECOVERABLE_ARG_CHECK_EXPECTED(
keyword != "smt-lib-version" || value == "2" || value == "2.0"
const std::string& value) const
{
CVC5_API_TRY_CATCH_BEGIN;
+ std::vector<std::string> options = options::getNames();
+ CVC5_API_UNSUPPORTED_CHECK(
+ option.find("command-verbosity") != std::string::npos
+ || std::find(options.cbegin(), options.cend(), option) != options.cend())
+ << "Unrecognized option: " << option << '.';
static constexpr auto mutableOpts = {"diagnostic-output-channel",
"print-success",
"regular-output-channel",
}
};
+/**
+ * Exception for unsupported command arguments.
+ * If thrown, API objects can still be used.
+ */
+class CVC5_EXPORT CVC5ApiUnsupportedException : public CVC5ApiRecoverableException
+{
+ public:
+ /**
+ * Construct with message from a string.
+ * @param str The error message.
+ */
+ CVC5ApiUnsupportedException(const std::string& str)
+ : CVC5ApiRecoverableException(str)
+ {
+ }
+ /**
+ * Construct with message from a string stream.
+ * @param stream The error message.
+ */
+ CVC5ApiUnsupportedException(const std::stringstream& stream)
+ : CVC5ApiRecoverableException(stream.str())
+ {
+ }
+};
+
/**
* An option-related API exception.
* If thrown, API objects can still be used.
solver->setInfo(d_flag, d_value);
d_commandStatus = CommandSuccess::instance();
}
- catch (api::CVC5ApiRecoverableException&)
+ catch (api::CVC5ApiUnsupportedException&)
{
// As per SMT-LIB spec, silently accept unknown set-info keys
d_commandStatus = CommandSuccess::instance();
}
+ catch (api::CVC5ApiRecoverableException& e)
+ {
+ d_commandStatus = new CommandRecoverableFailure(e.getMessage());
+ }
catch (exception& e)
{
d_commandStatus = new CommandFailure(e.what());
d_result = sexprToString(solver->mkTerm(api::SEXPR, v));
d_commandStatus = CommandSuccess::instance();
}
+ catch (api::CVC5ApiUnsupportedException&)
+ {
+ d_commandStatus = new CommandUnsupported();
+ }
catch (api::CVC5ApiRecoverableException& e)
{
- d_commandStatus = new CommandRecoverableFailure(e.what());
+ d_commandStatus = new CommandRecoverableFailure(e.getMessage());
}
catch (exception& e)
{
solver->setOption(d_flag, d_value);
d_commandStatus = CommandSuccess::instance();
}
- catch (api::CVC5ApiRecoverableException&)
+ catch (api::CVC5ApiUnsupportedException&)
{
d_commandStatus = new CommandUnsupported();
}
+ catch (api::CVC5ApiRecoverableException& e)
+ {
+ d_commandStatus = new CommandRecoverableFailure(e.getMessage());
+ }
catch (exception& e)
{
d_commandStatus = new CommandFailure(e.what());
d_result = solver->getOption(d_flag);
d_commandStatus = CommandSuccess::instance();
}
- catch (api::CVC5ApiRecoverableException&)
+ catch (api::CVC5ApiUnsupportedException&)
{
d_commandStatus = new CommandUnsupported();
}