Catching exceptions from C/C++ extensions
Andrew Gregory
Andrew.Gregory at npl.co.uk
Mon Jan 13 08:35:30 EST 2003
> Does:
>
> import mymodule
>
> try:
> y = myfunc()
> except mymodule.Myerror:
Thanks for the suggestion, but tried that. Get
AttributeError: 'module' object has no attribute "Myerror'
Andrew.
> -----Original Message-----
> From: Andrew Bennetts [mailto:andrew-pythonlist at puzzling.org]
> Sent: 13 January 2003 13:38
> To: Andrew Gregory
> Cc: python-list at python.org
> Subject: Re: Catching exceptions from C/C++ extensions
>
>
> 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.
>
-------------------------------------------------------------------
This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.
NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.
NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Teddington, Middlesex, United Kingdom TW11 0LW.
-------------------------------------------------------------------
More information about the Python-list
mailing list