Catching exceptions from C/C++ extensions
Andrew Bennetts
andrew-pythonlist at puzzling.org
Mon Jan 13 08:37:30 EST 2003
On Mon, Jan 13, 2003 at 04:37:06AM -0800, Andrew Gregory wrote:
> I've written an extension which defines it's own exception class:
>
> // In initialisation section
> static PyObject* Myerror;
>
> Myerror = PyErr_NewException("_mymodule.Myerror", NULL, NULL);
[..snip..]
> Which is just what I would expect. But if in a script file I have
> something like
>
> import mymodule
>
> try:
> y=myfunc()
> except Myerror:
>
> I get
>
> NameError: name 'Myerror' is not defined
Does:
import mymodule
try:
y = myfunc()
except mymodule.Myerror:
...
do what you want?
-Andrew.
More information about the Python-list
mailing list