Generating exceptions from C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jacob Kroon

    #1

    Generating exceptions from C

    Hi,

    I'm working on a python module written in C, and I'm trying to figure
    out how to raise python
    exceptions if a function fails. So far I've read
    http://docs.python.org/ext/errors.html and
    http://docs.python.org/api/exceptionHandling.html , but I've not fully
    understood it.

    I've managed to create the custom exception type using
    PyErr_NewExcept ion(), and if I do
    PyErr_SetString () the exception will get raised. Some questions:

    1. PyErr_NewExcept ion() creates the exception _class_, not the instance
    right ?

    2. Is PyErr_SetString () the correct way to raise exceptions ?

    3. Besides the error message I pass to PyErr_SetString (), I also want to
    pass additional return
    data together with the exception. But this should be attached to the
    exception _instance_,
    not the class, am I right ?

    4. If I am supposed to attach it to the exception instance, how would I
    do that ? I never have a
    pointer to the exception instance, just the class.

    --Jacob

Working...