ViennaGrid for Python
 All Classes Files Functions Variables
Public Member Functions | Public Attributes | List of all members
ExceptionTranslator< T > Struct Template Reference

Generic C++-to-Python exception translator. More...

#include <exception_translator.hpp>

Public Member Functions

 ExceptionTranslator (PyObject *py_except)
 Constructor of the exception translator.
void operator() (const T &cxx_except) const
 Call operator, which translates a C++ exception to a Python exception when called.

Public Attributes

PyObject * m_py_except
 Pointer to the type of the Python exception.

Detailed Description

template<typename T>
struct ExceptionTranslator< T >

Generic C++-to-Python exception translator.

This generic class accepts a C++ exception as the template parameter and a pointer to a Python exception as the constructor parameter. With that information, it implements the call operator that extracts the exception message from the C++ exception and translates the C++ exception to a Python exception with the same exception message.

Since
0.1.0

Constructor & Destructor Documentation

template<typename T >
ExceptionTranslator< T >::ExceptionTranslator ( PyObject *  py_except)
inline

Constructor of the exception translator.

Parameters
py_exceptPointer to the C type of the Python exception (in the form PyExc_<exception name>, e.g.: PyExc_IOError)
Since
0.1.0

Member Function Documentation

template<typename T >
void ExceptionTranslator< T >::operator() ( const T &  cxx_except) const
inline

Call operator, which translates a C++ exception to a Python exception when called.

Given the pointer to the type of the Python exception specified upon construction of the exception translator object, the call operator extracts the exception message from the C++ exception and translates the C++ exception to a Python exception with the same exception message.

In order to extract the exception message, this method calls the what() method on the exception object. Thus, the exception class must implement the what() method. This is true for C++'s STL exceptions, and you can implement the what() method in your own exception classes to return the exception message as a C string (const char *).

Parameters
cxx_exceptType of the C++ exception to be translated
Since
0.1.0

Member Data Documentation

template<typename T >
PyObject* ExceptionTranslator< T >::m_py_except

Pointer to the type of the Python exception.

Since
0.1.0

The documentation for this struct was generated from the following file: