59 exception::exception ( ) :
62 mBacktrace ( MaxExceptionHistoryLength , static_cast<void*> ( NULL ) ),
63 mThreadId (
boost::this_thread::get_id() ),
65 mString ( ( char* ) malloc ( 65536 ) ),
66 mAdditionalInfo ( ( char* ) malloc ( 65536 ) )
68 gettimeofday ( &mTime, NULL );
70 Backtrace::Backtrace ( mBacktrace );
72 mAdditionalInfo[0] =
'\0';
76 exception::exception (
const exception& aExc ) :
79 mBacktrace ( aExc.mBacktrace ),
80 mThreadId ( aExc.mThreadId ),
83 mString ( ( char* ) malloc ( 65536 ) ),
84 mAdditionalInfo ( ( char* ) malloc ( 65536 ) )
86 strcpy ( mAdditionalInfo , aExc.mAdditionalInfo );
91 strcpy ( mAdditionalInfo , aExc.mAdditionalInfo );
93 mBacktrace = aExc.mBacktrace;
94 mThreadId = aExc.mThreadId;
100 exception::~exception() throw()
108 if ( mAdditionalInfo )
110 free ( mAdditionalInfo );
111 mAdditionalInfo = NULL;
116 const char* exception::what()
const throw()
118 if ( mString == NULL )
120 std::cout <<
"Could not allocate memory for exception message" << std::endl;
124 std::stringstream lStr;
129 gettimeofday ( &lTime, NULL );
131 #ifdef COURTEOUS_EXCEPTIONS 132 lStr <<
"I'm terribly sorry to have to tell you this, but it appears that there was an exception:\n";
134 lStr <<
" * Exception type: ";
138 std::size_t lSize ( 1024 );
139 char lDemangled[lSize];
140 lStr << abi::__cxa_demangle (
typeid ( *this ).name() , lDemangled , &lSize , &lStatus );
142 lStr <<
typeid ( *this ).name();
145 lStr <<
" * Description: " <<
description() <<
"\n";
147 if ( strlen ( mAdditionalInfo ) )
149 lStr <<
" * Additional Information:\n";
150 lStr << mAdditionalInfo;
153 boost::thread::id lThreadId ( boost::this_thread::get_id() );
155 if ( mThreadId == lThreadId )
157 lStr <<
" * Exception occured in the same thread as that in which it was caught (" << lThreadId <<
")\n";
161 lStr <<
" * Exception occured in thread with ID: " << mThreadId <<
"\n";
162 lStr <<
" * Current thread has ID: " << lThreadId <<
"\n";
165 lStr << std::setfill (
'0' );
167 strftime ( tmbuf,
sizeof tmbuf,
"%Y-%m-%d %H:%M:%S", localtime ( &mTime.tv_sec ) );
168 lStr <<
" * Exception constructed at time: " << tmbuf <<
'.' << std::setw ( 6 ) << mTime.tv_usec <<
"\n";
169 strftime ( tmbuf,
sizeof tmbuf,
"%Y-%m-%d %H:%M:%S", localtime ( &lTime.tv_sec ) );
170 lStr <<
" * Exception's what() function called at time: " << tmbuf <<
'.' << std::setw ( 6 ) << lTime.tv_usec <<
"\n";
172 lStr <<
" * Call stack:\n";
173 std::vector< Backtrace::TracePoint > lBacktrace = Backtrace::BacktraceSymbols ( mBacktrace );
174 uint32_t lCounter ( 0 );
177 for ( std::vector< Backtrace::TracePoint >::iterator lIt = lBacktrace.begin() +3 ; lIt != lBacktrace.end(); ++lIt , ++lCounter )
179 lStr <<
" [ " << std::setw ( 2 ) << lCounter <<
" ] " << lOutputCleaner ( lIt->function ) <<
"\n";
180 lStr <<
" at " << lIt->file <<
":" << lIt->line <<
"\n";
185 if ( strlen ( mAdditionalInfo ) )
187 lStr << mAdditionalInfo;
196 std::string lString ( lStr.str() );
197 strncpy ( mString , lString.c_str() , 65536 );
199 if ( lString.size() > 65536 )
201 strcpy ( mString+65530 ,
"..." );
208 void exception::append (
const char* aCStr )
throw()
210 strncat ( mAdditionalInfo, aCStr , 65536-strlen ( mAdditionalInfo ) );
static std::string TStyle(const uint32_t &aIndex)
Prefix the type-substitution index with a T
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
Parameterized Functor which parses and formats GCC call stack so that they are human readable...