forked from boostorg/throw_exception
Add test with error_info
This commit is contained in:
@ -17,6 +17,7 @@ compile-fail throw_exception_fail.cpp ;
|
|||||||
run throw_exception_test2.cpp ;
|
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 ;
|
||||||
|
|
||||||
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 ;
|
||||||
|
66
test/throw_exception_test5.cpp
Normal file
66
test/throw_exception_test5.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// Copyright 2018, 2019 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
//
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
|
#include <boost/exception/get_error_info.hpp>
|
||||||
|
#include <boost/exception/info.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
typedef boost::error_info<struct tag_error_code, int> error_code;
|
||||||
|
typedef boost::error_info<struct tag_error_string, std::string> error_string;
|
||||||
|
|
||||||
|
class my_exception: public std::exception, public boost::exception
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::throw_exception( my_exception() << error_code( 123 ) << error_string( "error%%string" ) );
|
||||||
|
}
|
||||||
|
catch( boost::exception const & x )
|
||||||
|
{
|
||||||
|
{
|
||||||
|
int const * code = boost::get_error_info<error_code>( x );
|
||||||
|
|
||||||
|
BOOST_TEST( code != 0 );
|
||||||
|
BOOST_TEST_EQ( *code, 123 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string const * str = boost::get_error_info<error_string>( x );
|
||||||
|
|
||||||
|
BOOST_TEST( str != 0 );
|
||||||
|
BOOST_TEST_EQ( *str, "error%%string" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
BOOST_THROW_EXCEPTION( my_exception() << error_code( 123 ) << error_string( "error%%string" ) );
|
||||||
|
}
|
||||||
|
catch( boost::exception const & x )
|
||||||
|
{
|
||||||
|
{
|
||||||
|
int const * code = boost::get_error_info<error_code>( x );
|
||||||
|
|
||||||
|
BOOST_TEST( code != 0 );
|
||||||
|
BOOST_TEST_EQ( *code, 123 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string const * str = boost::get_error_info<error_string>( x );
|
||||||
|
|
||||||
|
BOOST_TEST( str != 0 );
|
||||||
|
BOOST_TEST_EQ( *str, "error%%string" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user