cppad_error#

View page source

Converting CppAD Errors To Python Exceptions#

Code#

The following CppAD error handler is created in the empty namespace corresponding to the cppad_error.cpp file:

   CppAD::ErrorHandler cppad_error(handler);

handler#

The error handler includes the following information in the exception message:

Label

Description

file

The name of the CppAD file where the error occurred.

line

The line number in the file where the error occurred.

exp

The c++ logical expression that should have been true.

msg

A descriptive error message about the problem.

C++ throw#

A std::runtime_error cpp_err is thrown with cpp_err.what() a string containing the information above.

Python raise#

The swig wrapper for each call to CppAD will catch the std::runtime_error and raise a python RuntimeError py_err where str( py_err ) is a string containing the information above.

Example#