2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-02-09 11:12:37 +00:00

current_exception_diagnostic_output.hpp

This commit is contained in:
Emil Dotchevski
2018-12-04 19:21:17 -08:00
parent 4ad8f9341d
commit fb942e5ca7
5 changed files with 64 additions and 48 deletions

View File

@@ -5,6 +5,7 @@
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/leaf/common.hpp>
#include <boost/leaf/current_exception_diagnostic_output.hpp>
#include <boost/leaf/error_capture.hpp>
#include <boost/leaf/error.hpp>
#include <boost/leaf/exception_capture.hpp>

View File

@@ -0,0 +1,54 @@
//Copyright (c) 2018 Emil Dotchevski
//Copyright (c) 2018 Second Spectrum, 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_17228D24F83C11E8AAC53F8F652D5A5F
#define UUID_17228D24F83C11E8AAC53F8F652D5A5F
#include <boost/leaf/exception_capture.hpp>
namespace boost { namespace leaf {
template <class... E>
void current_exception_diagnostic_output( std::ostream & os, expect<E...> const & exp )
{
os << "Current Exception Diagnostic Information:" << std::endl;
try
{
throw;
}
catch( std::exception const & ex )
{
os <<
"Exception dynamic type: " << typeid(ex).name() << std::endl <<
"std::exception::what(): " << ex.what() << std::endl;
}
catch( ... )
{
os << "Unknown exception type (not a std::exception)" << std::endl;
}
try
{
throw;
}
catch( leaf_detail::captured_exception const & e )
{
diagnostic_output_(os,e);
}
catch( error const & e )
{
diagnostic_output(os,exp,e);
}
catch( ... )
{
diagnostic_output(os,exp);
}
}
} }
#endif

View File

@@ -138,8 +138,8 @@ namespace boost { namespace leaf {
return 0;
}
virtual void diagnostic_output( std::ostream & ) const = 0;
virtual void unload( error const & ) noexcept = 0;
virtual void diagnostic_output_( std::ostream & ) const = 0;
virtual void unload_( error const & ) noexcept = 0;
};
////////////////////////////////////////
@@ -163,12 +163,12 @@ namespace boost { namespace leaf {
return tuple_for_each_capture<sizeof...(T),std::tuple<optional<T>...>>::dynamic_bind(s_,type_id);
}
void diagnostic_output( std::ostream & os ) const
void diagnostic_output_( std::ostream & os ) const
{
leaf_detail::tuple_for_each_capture<sizeof...(T),decltype(s_)>::print(os,s_);
}
void unload( error const & e ) noexcept
void unload_( error const & e ) noexcept
{
leaf_detail::tuple_for_each_capture<sizeof...(T),decltype(s_)>::unload(e,std::move(s_));
}
@@ -269,7 +269,7 @@ namespace boost { namespace leaf {
{
if( ds_ )
{
ds_->unload(e_);
ds_->unload_(e_);
free();
}
return e_;
@@ -304,7 +304,7 @@ namespace boost { namespace leaf {
inline void diagnostic_output( std::ostream & os, error_capture const & e )
{
if( e )
e.ds_->diagnostic_output(os);
e.ds_->diagnostic_output_(os);
}
} }

View File

@@ -44,7 +44,7 @@ namespace boost { namespace leaf {
std::rethrow_exception(ex_);
}
friend void diagnostic_output( std::ostream & os, captured_exception const & ce )
friend void diagnostic_output_( std::ostream & os, captured_exception const & ce )
{
diagnostic_output(os,static_cast<error_capture const &>(ce));
}
@@ -103,45 +103,6 @@ namespace boost { namespace leaf {
}
}
////////////////////////////////////////
template <class... E>
void current_exception_diagnostic_output( std::ostream & os, expect<E...> const & exp )
{
os << "Current Exception Diagnostic Information:" << std::endl;
try
{
throw;
}
catch( std::exception const & ex )
{
os <<
"Exception dynamic type: " << typeid(ex).name() << std::endl <<
"std::exception::what(): " << ex.what() << std::endl;
}
catch( ... )
{
os << "Unknown exception type (not a std::exception)" << std::endl;
}
try
{
throw;
}
catch( leaf_detail::captured_exception const & e )
{
diagnostic_output(os,e);
}
catch( error const & e )
{
diagnostic_output(os,exp,e);
}
catch( ... )
{
diagnostic_output(os,exp);
}
}
} }
#endif