[test] Unexpected Exceptions
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? Best regards, fw
[Please do not mail me a copy of your followup] boost-users@lists.boost.org spake the secret code <4B018783.7040603@motama.com> thusly:
What is the intended behavior of Boost.Test if an unexpected exception is thrown? Example:
void do_not_throw() throw() { throw "unexpected"; }
Should that really be decorated with throw()? At any rate, I'd expect the test to fail. -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/ Legalize Adulthood! http://legalizeadulthood.wordpress.com
Richard wrote:
[Please do not mail me a copy of your followup]
boost-users@lists.boost.org spake the secret code <4B018783.7040603@motama.com> thusly:
What is the intended behavior of Boost.Test if an unexpected exception is thrown? Example:
void do_not_throw() throw() { throw "unexpected"; }
Should that really be decorated with throw()?
At any rate, I'd expect the test to fail.
So would I. My problem is that the test does _not_ fail. Sorry, if I wasn't clear enough.
Florian Winter
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? It seems that MSVC for example does not follow standard here: http://msdn.microsoft.com/en-us/library/7twc8dwy(VS.80).aspx gcc seems to be aborting the application. Gennadiy
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
Florian Winter wrote:
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:
In current state Boost.Test does not try to handle unexpected exceptions, but in my experiments I was not able to do anything meaningful inside the framework to help handle this error.
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?
From that page: The C++ Standard requires that unexpected is called when a function throws an exception that is not on its throw list. The current implementation does not support this. Gennadiy
participants (3)
-
Florian Winter
-
Gennadiy Rozental
-
legalize+jeeves@mail.xmission.com