forked from boostorg/exception
added functions current_exception_cast, current_exception_diagnostic_information, various other minor changes, documentation update
[SVN r52236]
This commit is contained in:
34
include/boost/exception/current_exception_cast.hpp
Normal file
34
include/boost/exception/current_exception_cast.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
//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_7E83C166200811DE885E826156D89593
|
||||
#define UUID_7E83C166200811DE885E826156D89593
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
template <class E>
|
||||
inline
|
||||
E *
|
||||
current_exception_cast()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
E & e )
|
||||
{
|
||||
return &e;
|
||||
}
|
||||
catch(
|
||||
...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <boost/exception/current_exception_cast.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -18,6 +20,38 @@ boost
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <class T>
|
||||
struct
|
||||
enable_boost_exception_overload
|
||||
{
|
||||
typedef 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) };
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct
|
||||
enable_std_exception_overload
|
||||
{
|
||||
typedef 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) };
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
template <class T>
|
||||
inline
|
||||
std::string
|
||||
dynamic_exception_type( T const & x )
|
||||
{
|
||||
return std::string("Dynamic exception type: ") + BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
|
||||
}
|
||||
#endif
|
||||
|
||||
inline
|
||||
char const *
|
||||
get_diagnostic_information( exception const & x )
|
||||
@ -36,33 +70,76 @@ boost
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
boost_diagnostic_information( exception const & x )
|
||||
{
|
||||
std::ostringstream tmp;
|
||||
if( char const * const * f=get_error_info<throw_file>(x) )
|
||||
{
|
||||
tmp << *f;
|
||||
if( int const * l=get_error_info<throw_line>(x) )
|
||||
tmp << '(' << *l << "): ";
|
||||
}
|
||||
tmp << "Throw in function ";
|
||||
if( char const * const * fn=get_error_info<throw_function>(x) )
|
||||
tmp << *fn;
|
||||
else
|
||||
tmp << "(unknown)";
|
||||
tmp << std::endl;
|
||||
#ifndef BOOST_NO_RTTI
|
||||
tmp << dynamic_exception_type(x) << std::endl;
|
||||
if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
|
||||
tmp << "std::exception::what: " << e->what() << std::endl;
|
||||
#endif
|
||||
if( char const * s=exception_detail::get_diagnostic_information(x) )
|
||||
if( *s )
|
||||
tmp << s;
|
||||
return tmp.str();
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
std_diagnostic_information( std::exception const & x )
|
||||
{
|
||||
std::ostringstream tmp;
|
||||
#ifndef BOOST_NO_RTTI
|
||||
if( exception const * e=dynamic_cast<exception const *>(&x) )
|
||||
return boost_diagnostic_information(*e);
|
||||
tmp << dynamic_exception_type(x) << std::endl;
|
||||
#endif
|
||||
tmp << "std::exception::what: " << x.what() << std::endl;
|
||||
return tmp.str();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
|
||||
diagnostic_information( T const & e )
|
||||
{
|
||||
return exception_detail::boost_diagnostic_information(e);
|
||||
}
|
||||
|
||||
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::std_diagnostic_information(e);
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
diagnostic_information( exception const & x )
|
||||
current_exception_diagnostic_information()
|
||||
{
|
||||
std::ostringstream tmp;
|
||||
if( boost::shared_ptr<char const * const> f=get_error_info<throw_file>(x) )
|
||||
{
|
||||
tmp << *f;
|
||||
if( boost::shared_ptr<int const> l=get_error_info<throw_line>(x) )
|
||||
tmp << '(' << *l << "): ";
|
||||
}
|
||||
tmp << "Throw in function ";
|
||||
if( boost::shared_ptr<char const * const> fn=get_error_info<throw_function>(x) )
|
||||
tmp << *fn;
|
||||
if( boost::exception const * e=current_exception_cast<boost::exception const>() )
|
||||
return diagnostic_information(*e);
|
||||
else if( std::exception const * e=current_exception_cast<std::exception const>() )
|
||||
return diagnostic_information(*e);
|
||||
else
|
||||
tmp << "(unknown)";
|
||||
#ifndef BOOST_NO_RTTI
|
||||
tmp << "\nDynamic exception type: " << BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
|
||||
if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
|
||||
tmp << "\nstd::exception::what: " << e->what();
|
||||
#endif
|
||||
if( char const * s=exception_detail::get_diagnostic_information(x) )
|
||||
if( *s )
|
||||
tmp << '\n' << s;
|
||||
return tmp.str();
|
||||
return "No diagnostic information available.";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
@ -17,82 +17,12 @@ boost
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
struct
|
||||
strwrap
|
||||
{
|
||||
std::string str;
|
||||
char const * ptr;
|
||||
|
||||
explicit
|
||||
strwrap( char const * s ):
|
||||
str(s),
|
||||
ptr(&str[0])
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
strwrap( strwrap const & );
|
||||
strwrap & operator=( strwrap const & );
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
get_info<throw_function>
|
||||
{
|
||||
static
|
||||
shared_ptr<char const * const>
|
||||
get( exception const & x )
|
||||
{
|
||||
if( x.throw_function_ && *x.throw_function_ )
|
||||
{
|
||||
shared_ptr<strwrap> s(new strwrap(x.throw_function_));
|
||||
return shared_ptr<char const *>(s,&s->ptr);
|
||||
}
|
||||
else
|
||||
return shared_ptr<char const * const>();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
get_info<throw_file>
|
||||
{
|
||||
static
|
||||
shared_ptr<char const * const>
|
||||
get( exception const & x )
|
||||
{
|
||||
if( x.throw_file_ && *x.throw_file_ )
|
||||
{
|
||||
shared_ptr<strwrap> s(new strwrap(x.throw_file_));
|
||||
return shared_ptr<char const *>(s,&s->ptr);
|
||||
}
|
||||
else
|
||||
return shared_ptr<char const * const>();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
get_info<throw_line>
|
||||
{
|
||||
static
|
||||
shared_ptr<int const>
|
||||
get( exception const & x )
|
||||
{
|
||||
if( x.throw_line_!=-1 )
|
||||
return boost::shared_ptr<int>(new int(x.throw_line_));
|
||||
else
|
||||
return shared_ptr<int const>();
|
||||
}
|
||||
};
|
||||
|
||||
template <class ErrorInfo>
|
||||
struct
|
||||
get_info
|
||||
{
|
||||
static
|
||||
shared_ptr<typename ErrorInfo::value_type const>
|
||||
typename ErrorInfo::value_type const *
|
||||
get( exception const & x )
|
||||
{
|
||||
if( exception_detail::error_info_container * c=x.data_.get() )
|
||||
@ -102,9 +32,45 @@ boost
|
||||
BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
|
||||
#endif
|
||||
ErrorInfo const * w = static_cast<ErrorInfo const *>(eib.get());
|
||||
return shared_ptr<typename ErrorInfo::value_type const>(eib,&w->value());
|
||||
return &w->value();
|
||||
}
|
||||
return shared_ptr<typename ErrorInfo::value_type const>();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
get_info<throw_function>
|
||||
{
|
||||
static
|
||||
char const * const *
|
||||
get( exception const & x )
|
||||
{
|
||||
return x.throw_function_ ? &x.throw_function_ : 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
get_info<throw_file>
|
||||
{
|
||||
static
|
||||
char const * const *
|
||||
get( exception const & x )
|
||||
{
|
||||
return x.throw_file_ ? &x.throw_file_ : 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
get_info<throw_line>
|
||||
{
|
||||
static
|
||||
int const *
|
||||
get( exception const & x )
|
||||
{
|
||||
return x.throw_line_!=-1 ? &x.throw_line_ : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -112,7 +78,7 @@ boost
|
||||
#ifdef BOOST_NO_RTTI
|
||||
template <class ErrorInfo>
|
||||
inline
|
||||
shared_ptr<typename ErrorInfo::value_type const>
|
||||
typename ErrorInfo::value_type const *
|
||||
get_error_info( boost::exception const & x )
|
||||
{
|
||||
return exception_detail::get_info<ErrorInfo>::get(x);
|
||||
@ -120,13 +86,13 @@ boost
|
||||
#else
|
||||
template <class ErrorInfo,class E>
|
||||
inline
|
||||
shared_ptr<typename ErrorInfo::value_type const>
|
||||
typename ErrorInfo::value_type const *
|
||||
get_error_info( E const & some_exception )
|
||||
{
|
||||
if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
|
||||
return exception_detail::get_info<ErrorInfo>::get(*x);
|
||||
else
|
||||
return shared_ptr<typename ErrorInfo::value_type const>();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
@ -102,17 +102,13 @@ boost
|
||||
{
|
||||
if( diagnostic_info_str_.empty() )
|
||||
{
|
||||
std::string tmp;
|
||||
std::ostringstream tmp;
|
||||
for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
|
||||
{
|
||||
shared_ptr<error_info_base const> const & x = i->second;
|
||||
tmp += '[';
|
||||
tmp += x->tag_typeid_name();
|
||||
tmp += "] = ";
|
||||
tmp += x->value_as_string();
|
||||
tmp += '\n';
|
||||
tmp << '[' << x->tag_typeid_name() << "] = " << x->value_as_string() << std::endl;
|
||||
}
|
||||
diagnostic_info_str_.swap(tmp);
|
||||
tmp.str().swap(diagnostic_info_str_);
|
||||
}
|
||||
return diagnostic_info_str_.c_str();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 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)
|
||||
|
Reference in New Issue
Block a user