forked from boostorg/exception
get_error_info returns raw pointer instead of shared_ptr (breaking change)
diagnostic_information can now be called with boost::exception or std::exception object. BOOST_THROW_EXCEPTION can now be used even if exceptions are disabled. added functions: current_exception_diagnostic_information, current_exception_cast documentation updated to match. [SVN r52225]
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user