TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/common/exceptions.cpp
Go to the documentation of this file.
00001 #include "exceptions.hpp"
00002 
00003 namespace tuttle {
00004 namespace exception {
00005 
00006 std::string format_exception_message( const ::boost::exception& e )
00007 {
00008         std::ostringstream tmp;
00009         if( const ::boost::error_info_sstream* m = ::boost::get_error_info<tuttle::exception::user>(e) )
00010         {
00011                 tmp << *m;
00012                 return tmp.str();
00013         }
00014         else if( const ::boost::error_info_sstream* m = boost::get_error_info<tuttle::exception::dev>(e) )
00015         {
00016                 tmp << *m;
00017                 return tmp.str();
00018         }
00019         return std::string();
00020 }
00021 
00022 std::string format_exception_info( const ::boost::exception& e )
00023 {
00024         std::ostringstream tmp;
00025         if( ::boost::get_error_info<tuttle::exception::user>(e) )
00026         {
00027                 if( const ::boost::error_info_sstream* m = ::boost::get_error_info<tuttle::exception::dev>(e) )
00028                 {
00029                         tmp << " * Advanced message: " << *m << std::endl;
00030                 }
00031         }
00032         if( const ::std::string* m = ::boost::get_error_info<tuttle::exception::pluginIdentifier>(e) )
00033         {
00034                 tmp << " * Plugin identifier: " << *m << std::endl;
00035         }
00036         if( const ::std::string* m = ::boost::get_error_info<tuttle::exception::pluginName>(e) )
00037         {
00038                 tmp << " * Plugin name: " << *m << std::endl;
00039         }
00040         if( const ::std::string* m = ::boost::get_error_info<tuttle::exception::nodeName>(e) )
00041         {
00042                 tmp << " * Node name: " << *m << std::endl;
00043         }
00044         if( const OfxTime* t = ::boost::get_error_info<tuttle::exception::time>(e) )
00045         {
00046                 tmp << " * Time: " << *t << std::endl;
00047         }
00048         tmp << "----------" << std::endl;
00049         tmp << " * Full exception information:" << std::endl;
00050         tmp << ::boost::current_exception_diagnostic_information() << std::endl;
00051 #ifdef TUTTLE_DEBUG
00052         tmp << std::endl;
00053         tmp << " * Backtrace:" << std::endl;
00054         tmp << ::boost::trace(e) << std::endl;
00055 #endif
00056         tmp << "----------" << std::endl;
00057         return tmp.str();
00058 }
00059 
00060 std::string format_current_exception()
00061 {
00062         std::ostringstream tmp;
00063         tmp << "----------" << std::endl;
00064         tmp << " * Full exception information:" << std::endl;
00065         tmp << ::boost::current_exception_diagnostic_information() << std::endl;
00066         tmp << "----------" << std::endl;
00067         return tmp.str();
00068 }
00069 
00070 }
00071 }