[Pythonmac-SIG] Catching exceptions with Python from a Shared Library

Jack Jansen jack@oratrix.nl
Thu, 16 Nov 2000 12:37:54 +0100


Recently, "Christian Reyes" <christian@rocketnetwork.com> said:
> Catching exceptions from a Shared Library
> 
> Using Phil Thompson's SIP tool, I've wrapped a C++ DLL into a Python shared
> library.
> However, I'm having major difficulties handling any exceptions that get
> thrown from the DLL into Python.
> 
> My question is, is this even possible with MAC Python?  Does Mac Python
> handle exceptions thrown from a DLL?
> If so, what do I need to do to get this to work?

I've done all the things I think I should do to make C++ libraries
work, i.e. I'm calling the __initialize routines and everything. But
I've never tried to use exceptions, so there's a chance that it
doesn't work. The other C++ feature that needs this support, dynamic
initializers, does work.

Note that you do have to catch the exception in your code: MacPython
can't catch it as it is a C program and hence knows nothing about
exceptions. But if the situation is as I understand (MacPython loading 
a dynamic module written by you, which calls a C++ DLL provided by
someone else) the dynamic module should be able to catch the
exception.

And, if it doesn't work: could you provide me with a simple example of 
how it fails, then I can look into it.
--
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