9 #include "IException.h"
21 #include "Application.h"
22 #include "Preference.h"
40 IException::IException() {
42 m_errorType = Unknown;
45 m_previousExceptions = NULL;
72 IException::IException(
ErrorType type,
const QString &message,
73 const char *fileName,
int lineNumber) {
77 m_previousExceptions = NULL;
80 m_message =
new QString(QString(message).trimmed());
81 m_fileName =
new QString(fileName);
82 m_lineNumber = lineNumber;
84 deleteEmptyMemberStrings();
110 IException::IException(
ErrorType type,
const char *message,
111 const char *fileName,
int lineNumber) {
115 m_previousExceptions = NULL;
118 m_message =
new QString(QString(message).trimmed());
119 m_fileName =
new QString(fileName);
120 m_lineNumber = lineNumber;
122 deleteEmptyMemberStrings();
124 m_what = buildWhat();
148 IException::IException(
ErrorType type,
const std::string &message,
149 const char *fileName,
int lineNumber) {
153 m_previousExceptions = NULL;
156 m_message =
new QString(QString(message.c_str()).trimmed());
157 m_fileName =
new QString(fileName);
158 m_lineNumber = lineNumber;
160 deleteEmptyMemberStrings();
162 m_what = buildWhat();
198 const char *fileName,
int lineNumber) {
202 m_previousExceptions = NULL;
205 m_message =
new QString(QString(message).trimmed());
206 m_fileName =
new QString(fileName);
207 m_lineNumber = lineNumber;
209 deleteEmptyMemberStrings();
211 append(caughtException);
245 ErrorType type,
const std::string &message,
246 const char *fileName,
int lineNumber) {
250 m_previousExceptions = NULL;
253 m_message =
new QString(QString(message.c_str()).trimmed());
254 m_fileName =
new QString(fileName);
255 m_lineNumber = lineNumber;
257 deleteEmptyMemberStrings();
259 append(caughtException);
293 const char *fileName,
int lineNumber) {
297 m_previousExceptions = NULL;
300 m_message =
new QString(message.trimmed());
301 m_fileName =
new QString(fileName);
302 m_lineNumber = lineNumber;
304 deleteEmptyMemberStrings();
306 append(caughtException);
315 IException::IException(
const IException &other) : exception(other) {
325 int length = strlen(other.
m_what);
326 m_what =
new char[length + 1];
447 if (errorString !=
"")
448 cerr << errorString.toLatin1().data() << endl;
462 QString errorString =
toString(printFileInfo);
463 if (errorString !=
"")
464 cerr << errorString.toLatin1().data() << endl;
483 exceptionsToConvert.append(*
this);
485 for (
int exceptionIndex = exceptionsToConvert.size() - 1;
488 const IException &exception(exceptionsToConvert.at(exceptionIndex));
490 bool exceptionIsBlank =
true;
498 exceptionIsBlank =
false;
504 exceptionIsBlank =
false;
507 if (message.size() && message[message.size() - 1] ==
'.')
508 message = message.mid(0, message.size() - 1);
513 exceptionIsBlank =
false;
520 if (!exceptionIsBlank)
538 bool reportFileLine =
true;
540 if (Preference::Preferences().hasGroup(
"ErrorFacility")) {
542 Preference::Preferences().findGroup(
"ErrorFacility");
544 QString fileLine = errorFacility[
"FileLine"][0];
545 reportFileLine = (fileLine.toUpper() ==
"ON");
567 bool usePvlFormat =
false;
569 if (Preference::Preferences().hasGroup(
"ErrorFacility")) {
571 Preference::Preferences().findGroup(
"ErrorFacility");
573 QString format = errorFacility[
"Format"][0];
574 usePvlFormat = (format.toUpper() ==
"PVL");
581 if (errors.
groups() != 0) {
582 stringstream stringStream;
583 stringStream << errors;
584 result = stringStream.str().c_str();
593 exceptionsToConvert.append(*
this);
595 for (
int exceptionIndex = exceptionsToConvert.size() - 1;
598 const IException &exception(exceptionsToConvert.at(exceptionIndex));
605 bool needsPeriod =
false;
609 if (message.size() && message[message.size() - 1] ==
'.')
610 message = message.mid(0, message.size() - 1);
613 result +=
" " + message;
627 if (result.size() && result[result.size() - 1] !=
'\n')
632 return result.trimmed();
674 vector<string> theStack;
675 StackTrace::GetStackTrace(&theStack);
678 for(
unsigned int i = 1; i < theStack.size(); i++) {
679 message += (theStack[i] +
"\n").c_str();
683 if (theStack.size() != 0) {
703 result =
"USER ERROR";
706 result =
"PROGRAMMER ERROR";
709 result =
"I/O ERROR";
728 const QString &
string) {
731 if(
string ==
"USER ERROR")
733 else if(
string ==
"PROGRAMMER ERROR")
735 else if(
string ==
"I/O ERROR")
753 char *result =
new char[whatStr.size() + 1];
754 strncpy(result, whatStr.toLatin1().data(), whatStr.size());
755 result[whatStr.size()] =
'\0';