[C++-sig] Strange about the C++ exception in Python

Grant grant.tang at gmail.com
Fri Jul 11 21:15:59 CEST 2008


By googling I found this comment:

"Many platforms and compilers are not able to consistently catch exceptions 
thrown across shared library boundaries."

Does that mean my problem is unsolvable?
I am really curious how you guys deal with c++ exceptions in Python?

Grant

"Grant" <grant.tang at gmail.com> wrote in message 
news:g5662v$rkg$1 at ger.gmane.org...
> Hi,
>
> We have exception classees which is inherited from std::exception class. I 
> implemented the what() function always return the exception class's name 
> and description string. When the exception is throwed in C++ code, python 
> interpreter could catch it as RuntimeError. Then I print out the first 
> word of this RuntimeError object's args[0], it should be the c++ exception 
> class's name.
>
> Now the problem is this method works some times. Since I put try/except in 
> the unit test phrase, compare the exception name with a string. Some times 
> it works fine, but sometimes exception name is just ''. I don't understand 
> why it work the way so randomly.
>
> I use unittest module and test_support of test module for my unit test 
> framework. Does it have anything with the unit test, or it's a 
> boost.python issue, or the Python interpreter just misses to catch c++ 
> exception sometime?
>
> I tried to use boost.python's translator, but it does not help.
>
> How do you guys handle the exception throwed in C++?
>
> Thanks for your suggestion,
> Grant 






More information about the Cplusplus-sig mailing list