30 #include "MsqError.hpp"
33 #ifdef MSQ_USE_OLD_IO_HEADERS
47 static const char*
const error_messages[] = {
52 "Data not initialized",
59 "No storage mode for PatchData",
71 assert(
sizeof(error_messages) ==
sizeof(
char*) * (
LAST_ERROR_CODE+1) );
92 return mErr.set_error( num, msg )
93 && mErr.push( functionName, fileName, lineNumber );
98 return mErr.set_error( num )
99 && mErr.push( functionName, fileName, lineNumber );
106 #if defined(HAVE_VSNPRINTF)
108 va_start( args, format );
109 vsnprintf( buffer,
sizeof(buffer), format, args );
111 #elif defined(HAVE__VSNPRINTF)
113 va_start( args, format );
114 _vsnprintf( buffer,
sizeof(buffer), format, args );
116 #elif defined(HAVE_VSPRINTF)
118 va_start( args, format );
119 vsprintf( buffer, format, args );
122 strncpy( buffer, format,
sizeof(buffer) );
123 buffer[
sizeof(buffer)-1] =
'\0';
126 return mErr.set_error( num, buffer )
127 && mErr.push( functionName, fileName, lineNumber );
130 bool MsqError::push(
const char*
function,
const char* file,
int line )
132 stackTrace.push_back( Trace(
function, file, line) );
158 msq_stdio::ostream&
operator<<( msq_stdio::ostream& str,
const MsqError::Trace& tr )
160 return (str << tr.function <<
" at " << tr.file <<
":" << tr.line);
165 str <<
"MESQUITE ERROR " << (int)err.error_code() <<
" : "
166 << err.error_message() << msq_stdio::endl;
168 MsqError::StackTrace::const_iterator iter = err.stack().begin();
169 const MsqError::StackTrace::const_iterator end = err.stack().end();
172 str <<
" at " << *iter << msq_stdio::endl;
175 for ( ; iter != end; ++iter)
176 str <<
" in " << *iter << msq_stdio::endl;
182 {
if (
error()) outputStream << *
this << msq_stdio::endl; }
msq_std::string errorMessage
virtual bool push(const char *function, const char *file, int line)
Add to back-trace of call stack.
virtual bool set_error(ErrorCode num, const char *msg=0)
Initialize the error object with the passed data.
MsqError()
Initialize to cleared state.
bool error() const
Check if an error has occured.
const char * error_message() const
Get error message.
const char * functionName
void clear()
resets error object to non-active state (no error).
virtual ~MsqError()
Destructor - empty but must declar virtual destrucor if virtual functions.
msq_stdio::ostream & operator<<(msq_stdio::ostream &s, const Matrix3D &A)
virtual ~MsqPrintError()
On destruction, conditionally prints error data.