24 #include "IsisDebug.h"
56 IException::IException() {
58 m_errorType = Unknown;
61 m_previousExceptions = NULL;
88 IException::IException(
ErrorType type,
const QString &message,
89 const char *fileName,
int lineNumber) {
93 m_previousExceptions = NULL;
96 m_message =
new QString(QString(message).trimmed());
97 m_fileName =
new QString(fileName);
98 m_lineNumber = lineNumber;
100 deleteEmptyMemberStrings();
102 m_what = buildWhat();
126 IException::IException(
ErrorType type,
const char *message,
127 const char *fileName,
int lineNumber) {
131 m_previousExceptions = NULL;
134 m_message =
new QString(QString(message).trimmed());
135 m_fileName =
new QString(fileName);
136 m_lineNumber = lineNumber;
138 deleteEmptyMemberStrings();
140 m_what = buildWhat();
164 IException::IException(
ErrorType type,
const std::string &message,
165 const char *fileName,
int lineNumber) {
169 m_previousExceptions = NULL;
172 m_message =
new QString(QString(message.c_str()).trimmed());
173 m_fileName =
new QString(fileName);
174 m_lineNumber = lineNumber;
176 deleteEmptyMemberStrings();
178 m_what = buildWhat();
214 const char *fileName,
int lineNumber) {
218 m_previousExceptions = NULL;
221 m_message =
new QString(QString(message).trimmed());
222 m_fileName =
new QString(fileName);
223 m_lineNumber = lineNumber;
225 deleteEmptyMemberStrings();
227 append(caughtException);
261 ErrorType type,
const std::string &message,
262 const char *fileName,
int lineNumber) {
266 m_previousExceptions = NULL;
269 m_message =
new QString(QString(message.c_str()).trimmed());
270 m_fileName =
new QString(fileName);
271 m_lineNumber = lineNumber;
273 deleteEmptyMemberStrings();
275 append(caughtException);
309 const char *fileName,
int lineNumber) {
313 m_previousExceptions = NULL;
316 m_message =
new QString(message.trimmed());
317 m_fileName =
new QString(fileName);
318 m_lineNumber = lineNumber;
320 deleteEmptyMemberStrings();
322 append(caughtException);
331 IException::IException(
const IException &other) : exception(other) {
341 int length = strlen(other.
m_what);
342 m_what =
new char[length + 1];
463 if (errorString !=
"")
464 cerr << errorString.toAscii().data() << endl;
478 QString errorString =
toString(printFileInfo);
479 if (errorString !=
"")
480 cerr << errorString.toAscii().data() << endl;
499 exceptionsToConvert.append(*
this);
501 for (
int exceptionIndex = exceptionsToConvert.size() - 1;
504 const IException &exception(exceptionsToConvert.at(exceptionIndex));
506 bool exceptionIsBlank =
true;
511 if (exception.m_errorType !=
Unknown) {
514 exceptionIsBlank =
false;
519 if (exception.m_message) {
520 exceptionIsBlank =
false;
521 QString message(*exception.m_message);
523 if (message.size() && message[message.size() - 1] ==
'.')
524 message = message.mid(0, message.size() - 1);
528 if (exception.m_fileName) {
529 exceptionIsBlank =
false;
530 errGroup +=
PvlKeyword(
"File", *exception.m_fileName);
532 if (exception.m_lineNumber != -1)
536 if (!exceptionIsBlank)
554 bool reportFileLine =
true;
556 if (Preference::Preferences().hasGroup(
"ErrorFacility")) {
558 Preference::Preferences().findGroup(
"ErrorFacility");
560 QString fileLine = errorFacility[
"FileLine"][0];
561 reportFileLine = (fileLine.toUpper() ==
"ON");
583 bool usePvlFormat =
false;
585 if (Preference::Preferences().hasGroup(
"ErrorFacility")) {
587 Preference::Preferences().findGroup(
"ErrorFacility");
589 QString format = errorFacility[
"Format"][0];
590 usePvlFormat = (format.toUpper() ==
"PVL");
597 if (errors.
groups() != 0) {
598 stringstream stringStream;
599 stringStream << errors;
600 result = stringStream.str().c_str();
609 exceptionsToConvert.append(*
this);
611 for (
int exceptionIndex = exceptionsToConvert.size() - 1;
614 const IException &exception(exceptionsToConvert.at(exceptionIndex));
617 if (exception.m_errorType !=
Unknown || exception.m_message) {
621 bool needsPeriod =
false;
622 if (exception.m_message) {
623 QString message(*exception.m_message);
625 if (message.size() && message[message.size() - 1] ==
'.')
626 message = message.mid(0, message.size() - 1);
629 result +=
" " + message;
633 if(includeFileInfo && exception.m_fileName) {
634 result +=
" in " + *exception.m_fileName;
635 if (exception.m_lineNumber != -1)
643 if (result.size() && result[result.size() - 1] !=
'\n')
648 return result.trimmed();
690 vector<string> theStack;
691 StackTrace::GetStackTrace(&theStack);
694 for(
unsigned int i = 1; i < theStack.size(); i++) {
695 message += (theStack[i] +
"\n").c_str();
699 if (theStack.size() != 0) {
719 result =
"USER ERROR";
722 result =
"PROGRAMMER ERROR";
725 result =
"I/O ERROR";
744 const QString &
string) {
747 if(
string ==
"USER ERROR")
749 else if(
string ==
"PROGRAMMER ERROR")
751 else if(
string ==
"I/O ERROR")
769 char *result =
new char[whatStr.size() + 1];
770 strncpy(result, whatStr.toAscii().data(), whatStr.size());
771 result[whatStr.size()] =
'\0';