469,927 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Generating exceptions from C


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.


Mar 18 '06 #1
0 740

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Marcin Rzeznicki | last post: by
1 post views Thread by Anonieko | last post: by
28 posts views Thread by Nutkin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.