[C++-sig] Strange about the C++ exception in Python
Grant
grant.tang at gmail.com
Fri Jul 11 01:30:40 CEST 2008
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