[C++-sig] Specific exception classes

Emmanuel Taurel etaurel at cells.es
Wed Nov 16 16:34:37 CET 2005


Hello everybody.

 

I am using BPL to wrap a C++ library and I would like to define my own
exception. Therefore, I have written one exception translator that I have
registered with the "register_exception_translator". My exception translator
looks like this (DevFailed is the name of the C++ exception class) 

 

void translator_dev_failed(const DevFailed &the_ex)

{

            PyObject *py_exc =
PyErr_NewException("PyTangoDs.DevFailed",NULL,NULL);

            PyErr_SetString(py_exc,the_ex.errors[0].desc.in());

}

 

In Python, I have:

 

from PyTangoDs import *

try:

    ...

 

except DevFailed,e:

    print 'Received a DevFailed exception:',e

except:

    print 'An unforeseen exception occured....'

 

The python interpreter complains that it does not know the DevFailed name
with this error :

 

Traceback (most recent call last):

  File "main.py", line 19, in ?

    except DevFailed,e:

NameError: name 'DevFailed' is not defined

 

My question is : How is it possible to have your own exception ?

 

Thank's for your answer

 

Sincerely

 

Emmanuel Taurel (etaurel at cells.es)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20051116/c57aaa2f/attachment.htm>


More information about the Cplusplus-sig mailing list