Unable to check exception with BOOST_CHECK_THROW
I am finding that the BOOST_CHECK_THROW is not catching an exception class I made. Below is how I am calling it: void test_read_FAIL_EMPTY_READ () { boost::uint32_t size = 0; boost::uint8_t* data = 0; boost::uint32_t length = 5; Memory_Map a_ref ( size ); BOOST_CHECK_THROW ( a_ref.read ( data, length ), errors::IO_Exception ); } The read function is suppose to throw an errors::IO_Exception(int) when it finds out that the length of the read exceeds the length of the Memory_Map. What I am finding out is that the exception is being thrown but no message from Boost telling me that exception errors::IO_Exception has occurred and calling this test a success. Have I used the wrong macro? Stephen
"Stephen Torri"
I am finding that the BOOST_CHECK_THROW is not catching an exception class I made. Below is how I am calling it:
void test_read_FAIL_EMPTY_READ () { boost::uint32_t size = 0; boost::uint8_t* data = 0; boost::uint32_t length = 5;
Memory_Map a_ref ( size ); BOOST_CHECK_THROW ( a_ref.read ( data, length ), errors::IO_Exception ); }
The read function is suppose to throw an errors::IO_Exception(int) when it finds out that the length of the read exceeds the length of the Memory_Map. What I am finding out is that the exception is being thrown but no message from Boost telling me that exception errors::IO_Exception has occurred and calling this test a success.
BOOST_CHECK_THROW is used to check that an exception *is* thrown (primarily as a responce to invalid input). So the the bahavior you describe is correct. In this case condition is true (ie exception is thrown), so with default log level no output is printed. Error is reported if there were no target exception occured.
Have I used the wrong macro?
Stephen
Gennadiy
participants (2)
-
Gennadiy Rozental
-
Stephen Torri