Base class for minxlib exceptions.
This class acts as a base for the various exceptions thrown by minxlib. This class is exposed as a Python class that is derived from Python's standard Exception class. Thus, subclasses of this one inherit Python's Exception interface.
- Note
- This class cannot be instantiated directly by client code (neither inside minxlib nor in the Python side of Minx). It is meant to be a common base from which other, specific types of errors are derived.
static PyObject* minxlib::exception::get_py_exception |
( |
type_info |
t) | |
|
|
staticprotected |
Retrieve Python exception class for specified C++ type.
- Parameters
-
t | C++ exception class/subclass typeid. |
- Returns
- Python exception class object corresponding to t.
When we raise a minxlib exception to inform the Python side of Minx of some problem, we need the Python exception class corresponding to the C++ exception type. This function retrieves the desired Python exception class object from the registry maintained by the minxlib::exception base class.
If a (direct or indirect) subclass of minxlib::exception fails to register a Python exception class corresponding to its C++ type, this function will return the Python exception class corresponding to the minxlib::exception class. If this ever happens, it indicates a bug in the implementation of type t!
Register subclass's pythonize function.
- Parameters
-
t | Subclass typeid. |
f | Pointer to subclass's pythonize function. |
- Returns
- Nothing really.
The main Python initialization module, python.cc, calls exception::pythonize() to export the entire minxlib exception class hierarchy to the Python parts of Minx. All subclasses of minxlib::exception are expected to implement a Pythonize function that takes care of exporting their respective Python interfaces. To ensure that minxlib::exception::pythonize() can call the Pythonize functions of subclasses, all direct subclasses of minxlib::exception should call this function to let the base exception class know the address of the subclass's Pythonize function.
- Note
- Only direct subclasses of minxlib::exception should use this function. If a subclass of a subclass of minxlib::exception registers its Pythonize function using this routine, it could happen that the indirect subclass's Pythonize function gets called before its base class's Pythonize function, which can mess up the Boost.Python interface initialization sequence. Base classes of subclasses of subclasses of minxlib::exception should provide their own mechanisms for registering the Pythonize functions of their subclasses.
To make the registration mechanism described above work, direct subclasses of minxlib::exception should declare a static bool variable and in its initializer, call this function.
template<typename T >
static void minxlib::exception::translate |
( |
const T & |
e) | |
|
|
staticprotected |
Generic Boost.Python exception translator.
- Parameters
-
e | C++ exception object that needs to be translated to Python. |
- Returns
- Nothing.
This function sets up an exception translator for an exception of type T, which is expected to be either minxlib::exception or one of its subclasses.
All these translators follow the same pattern, viz., calling PyErr_SetString() using the Python exception class corresponding to type T as stored in exception::m_py_exception_map. Thus, we can use a generic function for this purpose.