C built and raised exceptions are not being catched in Python code
A. Lloyd Flanagan
alloydflanagan at attbi.com
Wed Feb 26 17:09:10 EST 2003
WP <warrenpstma at _______.com.hotmail> wrote in message news:<b087a.5600$kf7.658052 at news20.bellglobal.com>...
> >
> > Of course, I'd like to catch C raised exceptions in Python
> > code also, but I don't see what might be failing.
>
>
> What do you mean, raise exception in C? Do you mean return a NULL from a method in a C extension?
> In C you have return codes of NULL. Any time you return NULL, an exception is raised. You set
> the exception type (global) and return NULL.
>
> Warren
It sounds to me like he means raising a C++ exception with the throw
statement. People tend to say 'C' when they mean 'C++', it causes a
lot of confusion.
Anyway, Vinco, I think the answer is that the C++ and python exception
mechanisms are totally different animals; python doesn't support C++
exceptions. This is pretty much inevitable since python is written in
C. Besides, C++ exceptions are really language-specific; it would
make it impossible to raise exceptions in other languages.
So what you'll have to do is catch your exception, set the global
value, and return a NULL (0) from your method. Of course, if you want
to extend python to catch C++ exceptions, I'm sure many people would
appreciate it. :)
More information about the Python-list
mailing list