Generating exceptions from C

J

Jacob Kroon

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_NewException(), and if I do
PyErr_SetString() the exception will get raised. Some questions:

1. PyErr_NewException() 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top