I am currently writing a C++ extension for Python using Boost.Python. A function in this extension may generate an exception containing information about the error (beyond
The answer given by Jack Edmonds defines a Python "exception" class that does not inherit Exception (or any other built-in Python exception class). So although it can be caught with
except my_cpp_extension.MyCPPException as e:
...
it can not be caught with the usual catch all
except Exception as e:
...
Here is how to create a custom Python exception class that does inherit Exception.