I’m implementing a Python extension module using Boost.Python. The module should define its own custom exception classes that inherit Exception. How do I do that?
I’m implementing a Python extension module using Boost.Python. The module should define its own
Share
The following function creates a new Python exception class and adds it to the current scope. If it is called in a module initialization function, then it is added to the module.
The first argument is the name of the new exception class. The second argument is the type object for the base class of the new exception class; it defaults to the type object for
Exception. The return value is the type object for the new exception class.Use the function as follows:
Call the function in the module initialization function and store the return value in a global variable:
Raise exception of type
MyModule.MyException: