exception_xam.cpp#

View page source

C++: 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  );
}