
Hi, Gennadiy Rozental wrote:
Florian Winter
writes: Hi,
What is the intended behavior of Boost.Test if an unexpected exception is thrown? Example:
void do_not_throw() throw() { throw "unexpected"; }
Some of my applications using Boost.Test seem exit with an error code of 0 (successful) if an unexpected exception is thrown. Is this the intended behavior?
What compiler are you using?
The problem has been observed with GCC 4.3.1. I am using Boost version 1.35.0, which is pretty old... Also, my actual test case is more complex. It involves shared libraries and Boost.Test being built in a custom way, so you shouldn't expect to be able to reproduce the problem using only the code snippet I provided above. (I am also aware that the code snippet does not make any sense. In a "real" unit test, the exception is thrown deeper in the stack hierarchy below either a throw() function or the main function of a thread. This is of course a bug in my software, and I would like to detect this bug by a unit test, which requires that the unit test fails in case of an unexpected exception) Before I provide more information, I would like to know what Boost.Test is _expected_ to do in the case of unexpected exceptions, so I know if I'm actually seeing a bug or expected behavior. In my test cases, I see output similar to the following when an unexpected exception is thrown: ----- Running 1 test case... terminate called after throwing an instance of 'const char*' *** No errors detected ----- and the process exits with a result value of 0. This looks like Boost.Test is "catching" the error (probably using set_unexpected), because otherwise, the process would not exit with a result value of 0.
It seems that MSVC for example does not follow standard here: http://msdn.microsoft.com/en-us/library/7twc8dwy(VS.80).aspx
How? What is the problem with MSVC and set_unexpected, and what are the consequences for the behavior of Boost.Test? Regards, Florian