forked from boostorg/exception
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:
39
include/boost/exception/detail/object_hex_dump.hpp
Normal file
39
include/boost/exception/detail/object_hex_dump.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
//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)
|
||||
|
||||
#ifndef UUID_6F463AC838DF11DDA3E6909F56D89593
|
||||
#define UUID_6F463AC838DF11DDA3E6909F56D89593
|
||||
|
||||
#include <iomanip>
|
||||
#include <typeinfo>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <class T>
|
||||
std::string
|
||||
object_hex_dump( T const & x, size_t max_size=16 )
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: ";
|
||||
size_t n=sizeof(T)>max_size?max_size:sizeof(T);
|
||||
s.fill('0');
|
||||
s.width(2);
|
||||
unsigned char const * b=reinterpret_cast<unsigned char const *>(&x);
|
||||
s << std::setw(2) << std::hex << (unsigned int)*b;
|
||||
for( unsigned char const * e=b+n; ++b!=e; )
|
||||
s << " " << std::setw(2) << std::hex << (unsigned int)*b;
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
27
include/boost/exception/diagnostic_information.hpp
Normal file
27
include/boost/exception/diagnostic_information.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
//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)
|
||||
|
||||
#ifndef UUID_0552D49838DD11DD90146B8956D89593
|
||||
#define UUID_0552D49838DD11DD90146B8956D89593
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
inline
|
||||
std::string
|
||||
diagnostic_information( std::exception const & x )
|
||||
{
|
||||
if( exception const * be = dynamic_cast<exception const *>(&x) )
|
||||
return be->diagnostic_information();
|
||||
else
|
||||
return std::string("[ what: ") + x.what() + ", type: " + typeid(x).name() + " ]";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -92,7 +92,7 @@ boost
|
||||
count_(0)
|
||||
{
|
||||
if( boost::exception * be1=dynamic_cast<boost::exception *>(this) )
|
||||
if( boost::exception const * be2=dynamic_cast<boost::exception const *>(&x) )
|
||||
if( boost::exception const * be2=dynamic_cast<boost::exception const *>(&x) )
|
||||
*be1 = *be2;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,18 @@ boost
|
||||
~error_info_injector() throw()
|
||||
{
|
||||
}
|
||||
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
return T::what();
|
||||
}
|
||||
|
||||
char const *
|
||||
diagnostic_information() const throw()
|
||||
{
|
||||
return exception::_diagnostic_information(T::what());
|
||||
}
|
||||
};
|
||||
|
||||
struct large_size { char c[256]; };
|
||||
|
@ -27,7 +27,7 @@ boost
|
||||
error_info_container:
|
||||
public exception_detail::counted_base
|
||||
{
|
||||
virtual char const * what( std::type_info const & ) const = 0;
|
||||
virtual char const * diagnostic_information( char const *, std::type_info const & ) const = 0;
|
||||
virtual shared_ptr<error_info_base const> get( std::type_info const & ) const = 0;
|
||||
virtual void set( shared_ptr<error_info_base const> const & ) = 0;
|
||||
};
|
||||
@ -51,17 +51,14 @@ boost
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
if( data_ )
|
||||
try
|
||||
{
|
||||
char const * w = data_->what(typeid(*this));
|
||||
BOOST_ASSERT(0!=w);
|
||||
return w;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
return typeid(*this).name();
|
||||
return diagnostic_information();
|
||||
}
|
||||
|
||||
virtual
|
||||
char const *
|
||||
diagnostic_information() const throw()
|
||||
{
|
||||
return _diagnostic_information(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -75,6 +72,22 @@ boost
|
||||
{
|
||||
}
|
||||
|
||||
char const *
|
||||
_diagnostic_information( char const * std_what ) const throw()
|
||||
{
|
||||
if( data_ )
|
||||
try
|
||||
{
|
||||
char const * w = data_->diagnostic_information(std_what,typeid(*this));
|
||||
BOOST_ASSERT(0!=w);
|
||||
return w;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
return std_what ? std_what : typeid(*this).name();
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
|
||||
//Force class exception to be abstract.
|
||||
//Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected.
|
||||
|
@ -85,13 +85,6 @@ virtual //Disable bogus GCC warning.
|
||||
value_type const value_;
|
||||
};
|
||||
|
||||
template <class ErrorInfo>
|
||||
struct
|
||||
error_info_type
|
||||
{
|
||||
typedef typename ErrorInfo::value_type value_type;
|
||||
};
|
||||
|
||||
template <class E,class Tag,class T>
|
||||
E const &
|
||||
operator<<( E const & x, error_info<Tag,T> const & v )
|
||||
@ -155,11 +148,18 @@ virtual //Disable bogus GCC warning.
|
||||
}
|
||||
|
||||
char const *
|
||||
what( std::type_info const & exception_type ) const
|
||||
diagnostic_information( char const * std_what, std::type_info const & exception_type ) const
|
||||
{
|
||||
if( what_.empty() )
|
||||
{
|
||||
std::string tmp(exception_type.name());
|
||||
std::string tmp;
|
||||
if( std_what )
|
||||
{
|
||||
tmp += std_what;
|
||||
tmp += '\n';
|
||||
}
|
||||
tmp += "Dynamic exception type: ";
|
||||
tmp += exception_type.name();
|
||||
tmp += '\n';
|
||||
for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
|
||||
{
|
||||
|
@ -53,6 +53,20 @@ boost
|
||||
{
|
||||
enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
|
||||
};
|
||||
|
||||
template <class T,class U>
|
||||
std::string
|
||||
to_string( std::pair<T,U> const & x )
|
||||
{
|
||||
return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
to_string( std::exception const & x )
|
||||
{
|
||||
return x.what();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -7,9 +7,8 @@
|
||||
#define UUID_E788439ED9F011DCB181F25B55D89593
|
||||
|
||||
#include <boost/exception/to_string.hpp>
|
||||
#include <iomanip>
|
||||
#include <typeinfo>
|
||||
#include <ios>
|
||||
#include <boost/exception/detail/object_hex_dump.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
@ -41,6 +40,23 @@ boost
|
||||
{
|
||||
return s(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static
|
||||
std::string
|
||||
convert( T const & x, std::string s )
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static
|
||||
std::string
|
||||
convert( T const & x, char const * s )
|
||||
{
|
||||
BOOST_ASSERT(s!=0);
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
@ -58,15 +74,7 @@ boost
|
||||
std::string
|
||||
string_stub_dump( T const & x )
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "[ type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: ";
|
||||
size_t n=sizeof(T)>16?16:sizeof(T);
|
||||
s.fill('0');
|
||||
s.width(2);
|
||||
for( unsigned char const * b=reinterpret_cast<unsigned char const *>(&x),* e=b+n; b!=e; ++b )
|
||||
s << std::setw(2) << std::hex << (unsigned int)*b << " ";
|
||||
s << "]";
|
||||
return s.str();
|
||||
return "[ " + exception_detail::object_hex_dump(x) + " ]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,13 +91,6 @@ boost
|
||||
{
|
||||
return exception_detail::to_string_dispatch::dispatch(x,s);
|
||||
}
|
||||
|
||||
template <class T,class U>
|
||||
std::string
|
||||
to_string( std::pair<T,U> const & x )
|
||||
{
|
||||
return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user