forked from boostorg/exception
Merging changes from trunk.
[SVN r58421]
This commit is contained in:
@ -5,42 +5,79 @@
|
||||
|
||||
#ifndef UUID_0552D49838DD11DD90146B8956D89593
|
||||
#define UUID_0552D49838DD11DD90146B8956D89593
|
||||
#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
||||
#pragma warning(push,1)
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <boost/exception/detail/exception_ptr_base.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
#include <boost/exception/current_exception_cast.hpp>
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool );
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
current_exception_diagnostic_information()
|
||||
{
|
||||
boost::exception const * be=current_exception_cast<boost::exception const>();
|
||||
std::exception const * se=current_exception_cast<std::exception const>();
|
||||
if( be || se )
|
||||
return exception_detail::diagnostic_information_impl(be,se,true);
|
||||
else
|
||||
return "No diagnostic information available.";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <class T>
|
||||
struct
|
||||
enable_boost_exception_overload
|
||||
inline
|
||||
exception const *
|
||||
get_boost_exception( exception const * e )
|
||||
{
|
||||
struct yes { char q[100]; };
|
||||
typedef char no;
|
||||
static yes check(exception const *);
|
||||
static no check(...);
|
||||
enum e { value=sizeof(check((T*)0))==sizeof(yes) };
|
||||
};
|
||||
return e;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct
|
||||
enable_std_exception_overload
|
||||
inline
|
||||
exception const *
|
||||
get_boost_exception( ... )
|
||||
{
|
||||
struct yes { char q[100]; };
|
||||
typedef char no;
|
||||
static yes check(std::exception const *);
|
||||
static no check(...);
|
||||
enum e { value = !enable_boost_exception_overload<T>::value && sizeof(check((T*)0))==sizeof(yes) };
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline
|
||||
std::exception const *
|
||||
get_std_exception( std::exception const * e )
|
||||
{
|
||||
return e;
|
||||
}
|
||||
|
||||
inline
|
||||
std::exception const *
|
||||
get_std_exception( ... )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline
|
||||
char const *
|
||||
@ -65,12 +102,13 @@ boost
|
||||
std::string
|
||||
diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )
|
||||
{
|
||||
BOOST_ASSERT(be||se);
|
||||
if( !be && !se )
|
||||
return "Unknown exception.";
|
||||
#ifndef BOOST_NO_RTTI
|
||||
if( !se )
|
||||
se = dynamic_cast<std::exception const *>(be);
|
||||
if( !be )
|
||||
be = dynamic_cast<boost::exception const *>(se);
|
||||
be=dynamic_cast<boost::exception const *>(se);
|
||||
if( !se )
|
||||
se=dynamic_cast<std::exception const *>(be);
|
||||
#endif
|
||||
char const * wh=0;
|
||||
if( with_what && se )
|
||||
@ -97,7 +135,7 @@ boost
|
||||
}
|
||||
#ifndef BOOST_NO_RTTI
|
||||
tmp << std::string("Dynamic exception type: ") <<
|
||||
(be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
|
||||
(be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).type_.name() << '\n';
|
||||
#endif
|
||||
if( with_what && se )
|
||||
tmp << "std::exception::what: " << wh << '\n';
|
||||
@ -110,19 +148,10 @@ boost
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
|
||||
std::string
|
||||
diagnostic_information( T const & e )
|
||||
{
|
||||
return exception_detail::diagnostic_information_impl(&e,0,true);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
|
||||
diagnostic_information( T const & e )
|
||||
{
|
||||
return exception_detail::diagnostic_information_impl(0,&e,true);
|
||||
return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true);
|
||||
}
|
||||
|
||||
inline
|
||||
@ -147,40 +176,7 @@ boost
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
#include <boost/exception/current_exception_cast.hpp>
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
inline
|
||||
std::string
|
||||
current_exception_diagnostic_information()
|
||||
{
|
||||
boost::exception const * be=current_exception_cast<boost::exception const>();
|
||||
std::exception const * se=current_exception_cast<std::exception const>();
|
||||
if( be || se )
|
||||
return exception_detail::diagnostic_information_impl(be,se,true);
|
||||
else
|
||||
return "No diagnostic information available.";
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
diagnostic_information( exception_detail::exception_ptr_base const & p )
|
||||
{
|
||||
if( !p._empty() )
|
||||
try
|
||||
{
|
||||
p._rethrow();
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
return current_exception_diagnostic_information();
|
||||
}
|
||||
return "<empty>";
|
||||
}
|
||||
}
|
||||
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user