Add throw_exception_test6.cpp

This commit is contained in:
Peter Dimov
2022-01-26 07:11:12 +02:00
parent 7d804d72b8
commit 6624c33710
2 changed files with 54 additions and 0 deletions

View File

@ -27,6 +27,7 @@ run throw_exception_test2.cpp ;
run throw_exception_test3.cpp ; run throw_exception_test3.cpp ;
run throw_exception_test4.cpp ; run throw_exception_test4.cpp ;
run throw_exception_test5.cpp ; run throw_exception_test5.cpp ;
run throw_exception_test6.cpp ;
lib lib1_throw : lib1_throw.cpp : <define>LIB1_SOURCE=1 <link>shared:<define>LIB1_DYN_LINK=1 : : <link>shared:<define>LIB1_DYN_LINK=1 ; lib lib1_throw : lib1_throw.cpp : <define>LIB1_SOURCE=1 <link>shared:<define>LIB1_DYN_LINK=1 : : <link>shared:<define>LIB1_DYN_LINK=1 ;
lib lib2_throw : lib2_throw.cpp : <define>LIB2_SOURCE=1 <link>shared:<define>LIB2_DYN_LINK=1 : : <link>shared:<define>LIB2_DYN_LINK=1 ; lib lib2_throw : lib2_throw.cpp : <define>LIB2_SOURCE=1 <link>shared:<define>LIB2_DYN_LINK=1 : : <link>shared:<define>LIB2_DYN_LINK=1 ;

View File

@ -0,0 +1,53 @@
// Copyright 2018, 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/throw_exception.hpp>
#include <boost/core/lightweight_test.hpp>
class my_exception: public std::exception
{
};
class my_exception2: public std::exception, public virtual boost::exception
{
};
int main()
{
try
{
BOOST_THROW_EXCEPTION( my_exception() );
}
catch( std::exception const & x )
{
boost::source_location loc = boost::get_throw_location( x );
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST_EQ( loc.line(), 20 );
BOOST_TEST_CSTR_EQ( loc.function_name(), BOOST_CURRENT_FUNCTION );
}
catch( ... )
{
BOOST_ERROR( "'BOOST_THROW_EXCEPTION( my_exception() )' didn't throw 'std::exception'" );
}
try
{
BOOST_THROW_EXCEPTION( my_exception2() );
}
catch( boost::exception const & x )
{
boost::source_location loc = boost::get_throw_location( x );
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST_EQ( loc.line(), 37 );
BOOST_TEST_CSTR_EQ( loc.function_name(), BOOST_CURRENT_FUNCTION );
}
catch( ... )
{
BOOST_ERROR( "'BOOST_THROW_EXCEPTION( my_exception2() )' didn't throw 'boost::exception'" );
}
return boost::report_errors();
}