Add boost::throw_with_location

This commit is contained in:
Peter Dimov
2022-02-10 20:02:30 +02:00
parent 7b314a2184
commit c5dfcc3dd4
9 changed files with 316 additions and 5 deletions
+21
View File
@@ -20,6 +20,7 @@
#include "lib1_throw.hpp"
#include "lib2_throw.hpp"
#include "lib3_throw.hpp"
#include "lib4_throw.hpp"
#include <boost/exception/exception.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
@@ -30,6 +31,7 @@ void test_catch_by_type()
BOOST_TEST_THROWS( lib1::f(), lib1::exception );
BOOST_TEST_THROWS( lib2::f(), lib2::exception );
BOOST_TEST_THROWS( lib3::f(), lib3::exception );
BOOST_TEST_THROWS( lib4::f(), lib4::exception );
}
void test_catch_by_exception()
@@ -78,6 +80,25 @@ void test_throw_line()
BOOST_TEST( line != 0 );
BOOST_TEST_EQ( *line, 13 );
}
catch( ... )
{
BOOST_ERROR( "lib3::f failed to throw boost::exception" );
}
try
{
lib4::f();
}
catch( std::exception const & x )
{
boost::source_location loc = boost::get_throw_location( x );
BOOST_TEST_NE( loc.line(), 0 );
}
catch( ... )
{
BOOST_ERROR( "lib4::f failed to throw std::exception" );
}
}
int main()