\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
exception_xam.cpp#
View page sourceC++: CppAD Py Exception Handling: Example and Test#
# include <cstdio>
# include <string>
# include <cppad/py/cppad_py.hpp>
bool exception_xam(void) {
using std::string;
//
// initialize return variable
bool ok = true;
//------------------------------------------------------------------------
ok = false;
try {
throw std::runtime_error("test message");
} catch (std::runtime_error& e) {
string stored_message = e.what();
ok = stored_message == "test message";
}
return( ok );
}