BVB Source Codes

mars Show diagnostic_information.hpp Source code

Return Download mars: download diagnostic_information.hpp Source code - Download mars Source code - Type:.hpp
  1. //Copyright (c) 2006-2010 Emil Dotchevski and Reverge Studios, Inc.
  2.  
  3. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5.  
  6. #ifndef UUID_0552D49838DD11DD90146B8956D89593
  7. #define UUID_0552D49838DD11DD90146B8956D89593
  8. #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  9. #pragma GCC system_header
  10. #endif
  11. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  12. #pragma warning(push,1)
  13. #endif
  14.  
  15. #include <boost/config.hpp>
  16. #include <boost/exception/get_error_info.hpp>
  17. #include <boost/exception/info.hpp>
  18. #include <boost/utility/enable_if.hpp>
  19. #ifndef BOOST_NO_RTTI
  20. #include <boost/core/demangle.hpp>
  21. #endif
  22. #include <exception>
  23. #include <sstream>
  24. #include <string>
  25.  
  26. #ifndef BOOST_NO_EXCEPTIONS
  27. #include <boost/exception/current_exception_cast.hpp>
  28. namespace mars_boost {} namespace boost = mars_boost; namespace
  29. mars_boost
  30.     {
  31.     namespace
  32.     exception_detail
  33.         {
  34.         std::string diagnostic_information_impl( mars_boost::exception const *, std::exception const *, bool, bool );
  35.         }
  36.  
  37.     inline
  38.     std::string
  39.     current_exception_diagnostic_information( bool verbose=true)
  40.         {
  41.         mars_boost::exception const * be=current_exception_cast<mars_boost::exception const>();
  42.         std::exception const * se=current_exception_cast<std::exception const>();
  43.         if( be || se )
  44.             return exception_detail::diagnostic_information_impl(be,se,true,verbose);
  45.         else
  46.             return "No diagnostic information available.";
  47.         }
  48.     }
  49. #endif
  50.  
  51. namespace mars_boost {} namespace boost = mars_boost; namespace
  52. mars_boost
  53.     {
  54.     namespace
  55.     exception_detail
  56.         {
  57.         inline
  58.         exception const *
  59.         get_boost_exception( exception const * e )
  60.             {
  61.             return e;
  62.             }
  63.  
  64.         inline
  65.         exception const *
  66.         get_boost_exception( ... )
  67.             {
  68.             return 0;
  69.             }
  70.  
  71.         inline
  72.         std::exception const *
  73.         get_std_exception( std::exception const * e )
  74.             {
  75.             return e;
  76.             }
  77.  
  78.         inline
  79.         std::exception const *
  80.         get_std_exception( ... )
  81.             {
  82.             return 0;
  83.             }
  84.  
  85.         inline
  86.         char const *
  87.         get_diagnostic_information( exception const & x, char const * header )
  88.             {
  89. #ifndef BOOST_NO_EXCEPTIONS
  90.             try
  91.                 {
  92. #endif
  93.                 error_info_container * c=x.data_.get();
  94.                 if( !c )
  95.                     x.data_.adopt(c=new exception_detail::error_info_container_impl);
  96.                 char const * di=c->diagnostic_information(header);
  97.                 BOOST_ASSERT(di!=0);
  98.                 return di;
  99. #ifndef BOOST_NO_EXCEPTIONS
  100.                 }
  101.             catch(...)
  102.                 {
  103.                 return 0;
  104.                 }
  105. #endif
  106.             }
  107.  
  108.         inline
  109.         std::string
  110.         diagnostic_information_impl( mars_boost::exception const * be, std::exception const * se, bool with_what, bool verbose )
  111.             {
  112.             if( !be && !se )
  113.                 return "Unknown exception.";
  114. #ifndef BOOST_NO_RTTI
  115.             if( !be )
  116.                 be=dynamic_cast<mars_boost::exception const *>(se);
  117.             if( !se )
  118.                 se=dynamic_cast<std::exception const *>(be);
  119. #endif
  120.             char const * wh=0;
  121.             if( with_what && se )
  122.                 {
  123.                 wh=se->what();
  124.                 if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
  125.                     return wh;
  126.                 }
  127.             std::ostringstream tmp;
  128.             if( be && verbose )
  129.                 {
  130.                 char const * const * f=get_error_info<throw_file>(*be);
  131.                 int const * l=get_error_info<throw_line>(*be);
  132.                 char const * const * fn=get_error_info<throw_function>(*be);
  133.                 if( !f && !l && !fn )
  134.                     tmp << "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
  135.                 else
  136.                     {
  137.                     if( f )
  138.                         {
  139.                         tmp << *f;
  140.                         if( int const * l=get_error_info<throw_line>(*be) )
  141.                             tmp << '(' << *l << "): ";
  142.                         }
  143.                     tmp << "Throw in function ";
  144.                     if( char const * const * fn=get_error_info<throw_function>(*be) )
  145.                         tmp << *fn;
  146.                     else
  147.                         tmp << "(unknown)";
  148.                     tmp << '\n';
  149.                     }
  150.                 }
  151. #ifndef BOOST_NO_RTTI
  152.             if ( verbose )
  153.                 tmp << std::string("Dynamic exception type: ") <<
  154.                     core::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
  155. #endif
  156.             if( with_what && se && verbose )
  157.                 tmp << "std::exception::what: " << wh << '\n';
  158.             if( be )
  159.                 if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
  160.                     if( *s )
  161.                         return std::string(s);
  162.             return tmp.str();
  163.             }
  164.         }
  165.  
  166.     template <class T>
  167.     std::string
  168.     diagnostic_information( T const & e, bool verbose=true )
  169.         {
  170.         return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true,verbose);
  171.         }
  172.  
  173.     inline
  174.     char const *
  175.     diagnostic_information_what( exception const & e, bool verbose=true ) throw()
  176.         {
  177.         char const * w=0;
  178. #ifndef BOOST_NO_EXCEPTIONS
  179.         try
  180.             {
  181. #endif
  182.             (void) exception_detail::diagnostic_information_impl(&e,0,false,verbose);
  183.             if( char const * di=exception_detail::get_diagnostic_information(e,0) )
  184.                 return di;
  185.             else
  186.                 return "Failed to produce mars_boost::diagnostic_information_what()";
  187. #ifndef BOOST_NO_EXCEPTIONS
  188.             }
  189.         catch(
  190.         ... )
  191.             {
  192.             }
  193. #endif
  194.         return w;
  195.         }
  196.     }
  197.  
  198. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  199. #pragma warning(pop)
  200. #endif
  201. #endif
  202.  
downloaddiagnostic_information.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top