documentation update, added function exception::diagnostic_information, added std::exception to_string overload, removed tabs from source files

[SVN r46697]
This commit is contained in:
Emil Dotchevski
2008-06-25 23:27:56 +00:00
parent 1d776ff363
commit f58ffdd643
55 changed files with 6444 additions and 4613 deletions

View File

@ -7,7 +7,10 @@
import testing ;
project : requirements <exception-handling>on ;
#to_string
run is_output_streamable_test.cpp ;
run has_to_string_test.cpp ;
run to_string_test.cpp ;
@ -15,6 +18,7 @@ run to_string_stub_test.cpp ;
compile-fail to_string_fail.cpp ;
#exception
run cloning_test.cpp ;
run copy_exception_test.cpp ;
run unknown_exception_test.cpp ;
@ -24,11 +28,15 @@ run enable_error_info_test.cpp helper1.cpp ;
run throw_exception_test.cpp helper2.cpp ;
run errno_test.cpp ;
run error_info_test.cpp ;
run diagnostic_information_test.cpp ;
run what_test.cpp ;
compile-fail exception_fail.cpp ;
compile-fail throw_exception_fail.cpp ;
#headers
compile exception_ptr_hpp_test.cpp ;
compile diagnostic_information_hpp_test.cpp ;
compile enable_current_exception_hpp_test.cpp ;
compile enable_error_info_hpp_test.cpp ;
compile error_info_hpp_test.cpp ;

View File

@ -0,0 +1,6 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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/exception/diagnostic_information.hpp>

View File

@ -0,0 +1,80 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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/exception/diagnostic_information.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
typedef boost::error_info<struct tag,int> tag_int;
struct
error1:
public std::exception
{
char const *
what() const throw()
{
return "error1";
}
};
struct
error2:
public std::exception,
public boost::exception
{
char const *
what() const throw()
{
return "error2";
}
};
struct
error3:
public boost::exception
{
};
std::string
get_diagnostic_information( std::exception const & x )
{
return boost::diagnostic_information(x);
}
std::string
get_what( std::exception const & x )
{
return x.what();
}
int
main()
{
using namespace boost;
{
error1 x;
BOOST_TEST(get_what(x)=="error1");
std::string di=get_diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
BOOST_TEST(di.find("error1")!=std::string::npos);
}
{
error2 x; x << tag_int(42);
BOOST_TEST(get_what(x)=="error2");
std::string di=get_diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
BOOST_TEST(di.find("error2")!=std::string::npos);
}
{
error3 x;
x << tag_int(1);
std::string w1 = x.diagnostic_information();
x << tag_int(2);
std::string w2 = x.diagnostic_information();
BOOST_TEST( w1!=w2 );
}
return boost::report_errors();
}

View File

@ -5,6 +5,7 @@
#include "helper1.hpp"
#include <boost/exception/info.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/detail/lightweight_test.hpp>
namespace
@ -24,6 +25,11 @@ namespace
x << test_int(42);
throw;
}
catch(
... )
{
BOOST_TEST(false);
}
}
}
@ -39,6 +45,8 @@ main()
std::exception & x )
{
BOOST_TEST( 42==*boost::get_error_info<test_int>(x) );
BOOST_TEST( std::string(x.what())==std::string("exception test length error") );
BOOST_TEST( std::string(x.what())!=std::string(boost::diagnostic_information(x)) );
}
catch(
... )

View File

@ -18,7 +18,7 @@ typedef boost::error_info<struct tag_test_6,non_printable> test_6;
struct
test_exception:
public boost::exception
boost::exception
{
};
@ -110,6 +110,11 @@ test_empty()
BOOST_TEST( dynamic_cast<test_exception *>(&x) );
BOOST_TEST( !boost::get_error_info<test_1>(x) );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
@ -121,6 +126,11 @@ test_empty()
{
BOOST_TEST( dynamic_cast<boost::exception *>(&x) );
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
@ -136,6 +146,12 @@ test_basic_throw_catch()
{
BOOST_TEST(*boost::get_error_info<test_5>(x)==std::string("test"));
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw_test_2();
@ -146,6 +162,11 @@ test_basic_throw_catch()
{
BOOST_TEST(boost::get_error_info<test_6>(x));
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
@ -161,6 +182,11 @@ test_catch_add_info()
{
BOOST_TEST(*boost::get_error_info<test_5>(x)==std::string("test"));
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
@ -179,6 +205,11 @@ test_add_tuple()
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw test_exception() << test_123(42,42u,42.0f);
@ -190,6 +221,11 @@ test_add_tuple()
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
BOOST_TEST( *boost::get_error_info<test_3>(x)==42.0f );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw test_exception() << test_1235(42,42u,42.0f,std::string("42"));
@ -202,6 +238,11 @@ test_add_tuple()
BOOST_TEST( *boost::get_error_info<test_3>(x)==42.0f );
BOOST_TEST( *boost::get_error_info<test_5>(x)=="42" );
}
catch(
... )
{
BOOST_TEST(false);
}
}
int

View File

@ -0,0 +1,6 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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/exception_ptr.hpp>

View File

@ -16,7 +16,7 @@ boost
void
throw_length_error()
{
throw enable_error_info( std::length_error("my length error") );
throw enable_error_info( std::length_error("exception test length error") );
}
}
}

View File

@ -50,7 +50,10 @@ main()
catch(
boost::unknown_exception & x )
{
BOOST_TEST( 42==*boost::get_error_info<test>(x) );
if( boost::shared_ptr<int const> d=boost::get_error_info<test>(x) )
BOOST_TEST( 42==*d );
else
BOOST_TEST(false);
}
catch(
... )
@ -64,7 +67,10 @@ main()
catch(
boost::exception & x )
{
BOOST_TEST( 42==*boost::get_error_info<test>(x) );
if( boost::shared_ptr<int const> d=boost::get_error_info<test>(x) )
BOOST_TEST( 42==*d );
else
BOOST_TEST(false);
}
catch(
... )

View File

@ -3,25 +3,30 @@
//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/exception/info.hpp>
#include <boost/exception/exception.hpp>
#include <exception>
#include <string>
#include <boost/detail/lightweight_test.hpp>
typedef boost::error_info<struct tag_test,int> test;
class
my_exception:
public boost::exception
struct
test_exception:
std::exception,
boost::exception
{
char const *
what() const throw()
{
return "test_exception";
}
};
int
main()
{
my_exception x;
x << test(1);
std::string w1 = x.what();
x << test(2);
std::string w2 = x.what();
BOOST_TEST( w1!=w2 );
test_exception x;
std::exception & sx(x);
boost::exception & bx(x);
BOOST_TEST(std::string(sx.what())=="test_exception");
BOOST_TEST(std::string(bx.what())=="test_exception");
return boost::report_errors();
}