[Pythonmac-SIG] Catching exceptions with Python from a Shared Library
Jack Jansen
jack@oratrix.nl
Fri, 17 Nov 2000 00:03:36 +0100
Chris,
I've cc'd the SIG again, because I'd like these answers to be kept in
the archive. Hope you don't mind...
Recently, "Christian Reyes" <christian@rocketnetwork.com> said:
> You understand the situation completely. I was hoping that there was a way
> that python would catch the exception thrown from the DLL, but I now
> understand that it is the dynamic module that must catch it.
>
> But how can I send it back to Python as a python exception from the dynamic
> module? Is that possible?
You catch the C++ exception in the C++ way, and then you raise a
Python exception by calling one of the exception functions from
pyerrors.h and returning NULL from your function.
As I haven't done this before myself and may need to do so shortly
you'd do me a great favor if you could post a code snippet once you
have something working.
Oh yes: note that, even if MacPython could catch C++ exceptions, you
would really have to catch it in your module. You've probably
allocated objects and such that you need to free, and maybe other
cleanup to do.
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm