[C++-sig] Strange about the C++ exception in Python
grant.tang at gmail.com
Fri Jul 11 01:30:40 CEST 2008
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, it should be the c++ exception
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
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,
More information about the Cplusplus-sig