I am creating my own Python extension (using SWIG, but I hope that is not relevant).
In the C++ side of it, I am using PyErr_NewException to create a custom exception object.
// C++ - create a custom Python Exception class.
m = Py_InitModule((char *) "MyModule", SwigMethods);
g_pyMyErr = PyErr_NewException( "MyModule.MyErr", 0, 0 );
Py_INCREF(g_pyMyErr);
int result = PyModule_AddObject(m, "MyErr", g_pyMyErr);
The above code returns success values and I can throw the above exception successfully and catch it in the Python client code.
The problem is this: When I refer to "MyErr" in Python code I get an error saying "MyErr" is not defined.
// Python client code - catch the exception
from MyModule import *
try:
causeException()
catch MyErr: # Error: MyErr is not defined.
pass
catch Exception:
pass
EDIT: My current thinking is that maybe SWIG is altering (mangling) the names of things.