19#include "Application.h"
20#include "Preference.h"
71 const char *fileName,
int lineNumber) {
78 m_message =
new QString(QString(message).trimmed());
109 const char *fileName,
int lineNumber) {
116 m_message =
new QString(QString(message).trimmed());
147 const char *fileName,
int lineNumber) {
154 m_message =
new QString(QString(message.c_str()).trimmed());
196 const char *fileName,
int lineNumber) {
203 m_message =
new QString(QString(message).trimmed());
243 ErrorType type,
const std::string &message,
244 const char *fileName,
int lineNumber) {
251 m_message =
new QString(QString(message.c_str()).trimmed());
291 const char *fileName,
int lineNumber) {
298 m_message =
new QString(message.trimmed());
323 int length = strlen(other.m_what);
324 m_what = new char[length + 1];
325 strncpy(m_what, other.m_what, length);
326 m_what[length] =
'\0';
330 m_message = new QString(*other.m_message);
334 m_fileName = new QString(*other.m_fileName);
338 m_previousExceptions = new QList<IException>(*other.m_previousExceptions);
445 if (errorString !=
"")
446 cerr << errorString.toLatin1().data() << endl;
460 QString errorString =
toString(printFileInfo);
461 if (errorString !=
"")
462 cerr << errorString.toLatin1().data() << endl;
481 exceptionsToConvert.append(*
this);
483 for (
int exceptionIndex = exceptionsToConvert.size() - 1;
486 const IException &exception(exceptionsToConvert.at(exceptionIndex));
488 bool exceptionIsBlank =
true;
493 if (exception.m_errorType !=
Unknown) {
496 exceptionIsBlank =
false;
501 if (exception.m_message) {
502 exceptionIsBlank =
false;
503 QString message(*exception.m_message);
505 if (message.size() && message[message.size() - 1] ==
'.')
506 message = message.mid(0, message.size() - 1);
510 if (exception.m_fileName) {
511 exceptionIsBlank =
false;
512 errGroup +=
PvlKeyword(
"File", *exception.m_fileName);
514 if (exception.m_lineNumber != -1)
518 if (!exceptionIsBlank)
536 return toString(Preference::Preferences().reportFileLine());
554 if (Preference::Preferences().outputErrorAsPvl()) {
557 if (errors.
groups() != 0) {
558 stringstream stringStream;
559 stringStream << errors;
560 result = stringStream.str().c_str();
569 exceptionsToConvert.append(*
this);
571 for (
int exceptionIndex = exceptionsToConvert.size() - 1;
574 const IException &exception(exceptionsToConvert.at(exceptionIndex));
577 if (exception.m_errorType !=
Unknown || exception.m_message) {
581 bool needsPeriod =
false;
582 if (exception.m_message) {
583 QString message(*exception.m_message);
585 if (message.size() && message[message.size() - 1] ==
'.')
586 message = message.mid(0, message.size() - 1);
589 result +=
" " + message;
593 if(includeFileInfo && exception.m_fileName) {
594 result +=
" in " + *exception.m_fileName;
595 if (exception.m_lineNumber != -1)
603 if (result.size() && result[result.size() - 1] !=
'\n')
608 return result.trimmed();
655 result =
"USER ERROR";
658 result =
"PROGRAMMER ERROR";
661 result =
"I/O ERROR";
680 const QString &
string) {
683 if(
string ==
"USER ERROR")
685 else if(
string ==
"PROGRAMMER ERROR")
687 else if(
string ==
"I/O ERROR")
705 char *result =
new char[whatStr.size() + 1];
706 strncpy(result, whatStr.toLatin1().data(), whatStr.size());
707 result[whatStr.size()] =
'\0';
static QString Name()
Returns the name of the application.
ErrorType
Contains a set of exception error types.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
@ Io
A type of error that occurred when performing an actual I/O operation.
QString * m_message
The message associated with this exception.
IException()
The default constructor creates an IException instance with no message, previous exceptions,...
int m_lineNumber
The line in the source code file that threw this exception.
IException & operator=(const IException &rhs)
Assign the values of rhs to this instance.
static QString errorTypeToString(ErrorType t)
Returns the source of the error in string format for the given ErrorType.
const char * what() const
Returns a string representation of this exception in its current state.
char * m_what
This is used to store the return value of what() in a way that guarantees the returned data will not ...
ErrorType errorType() const
Returns the source of the error for this exception.
QString toString() const
Returns a string representation of this exception.
QList< IException > * m_previousExceptions
A list of exceptions that caused this exception.
ErrorType m_errorType
This exception's error source.
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
void print() const
Prints a string representation of this exception to stderr.
Pvl toPvl() const
Returns a PVL object representing the contents of this exception.
void swap(IException &other)
Swaps the values of this instance's member data with other.
char * buildWhat() const
Returns a C string containing a string representation of this exception.
~IException()
The destructor frees memory allocated for the message, filename, and list of previous exceptions.
void deleteEmptyMemberStrings()
This is a helper method for the constructors.
static ErrorType stringToErrorType(const QString &s)
Given a string, returns the error type associated with it.
QString * m_fileName
The source code file that threw this exception.
Contains multiple PvlContainers.
Container for cube-like labels.
A single keyword-value pair.
int groups() const
Returns the number of groups contained.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Namespace for the standard library.