BPS error exception class. More...
#include <bpsexception.h>
Public Types | |
enum | Severity { Info , Warning , Error , Fatal } |
Severity of the exception. More... | |
Public Member Functions | |
BpsException & | addLocation (const QString &aFilename, quint32 aLinenumber, const QString &aFunction) |
Add another location to an existing exception. More... | |
BpsException & | appendMessage (const QString &aText) |
Append text to the error message of the exception. More... | |
BpsException () | |
Default constructor for the BpsException objects. More... | |
BpsException (const BpsException &aException) | |
Copy constructor for the BpsException objects. More... | |
BpsException (const QScriptValue &aException, const QString &aFilename=QString()) | |
Constructor from QtScript exceptions. More... | |
BpsException (const QString &aFilename, quint32 aLinenumber, const QString &aFunction, const QString &aMessage, Severity aSeverity) | |
Standard constructor for the BpsException objects. More... | |
QString | message () const |
Get the plain message, without location trace information. More... | |
BpsException & | setMessage (const QString &aMessage) |
Set the error message for the exception. More... | |
BpsException & | setSeverity (Severity aSeverity) |
Set the error severity for the exception. More... | |
Severity | severity () const |
Get severity. More... | |
QString | text (int aMaxLocs=1) const |
Get the message, along with a log of the locations stack. More... | |
QScriptValue | throwScriptError (QScriptContext *aContext) const |
Throw a script error of the exception. More... | |
Related Functions | |
(Note that these are not member functions.) | |
#define | bpsMakeException(aMessage) BpsException(__FILE__, __LINE__, QString::fromLatin1(__FUNCTION__), aMessage, BpsException::Error) |
Convenience macro to create a BpsException with severity of Error. More... | |
#define | bpsMakeExceptionFatal(aMessage) BpsException(__FILE__, __LINE__, QString::fromLatin1(__FUNCTION__), aMessage, BpsException::Fatal) |
Convenience macro to create a BpsException with severity of Fatal. More... | |
#define | bpsMakeExceptionInfo(aMessage) BpsException(__FILE__, __LINE__, QString::fromLatin1(__FUNCTION__), aMessage, BpsException::Info) |
Convenience macro to create a BpsException with severity of Info. More... | |
#define | bpsMakeExceptionWarning(aMessage) BpsException(__FILE__, __LINE__, QString::fromLatin1(__FUNCTION__), aMessage, BpsException::Warning) |
Convenience macro to create a BpsException with severity of Warning. More... | |
#define | bpsTraceException(aException) aException.addLocation(__FILE__, __LINE__, QString::fromLatin1(__FUNCTION__)) |
Convenience macro to add a location to the traceback stack. More... | |
BPS error exception class.
In the BPS environment error handling is heavily using exceptions (in contrast to the underlying Qt framework, where exceptions are for historical reasons not used in c++ at all). The base class of all exceptions thrown by the BPS c++ library is BpsException.
The class holds an error message, plus an arbitrary number of locations made up each by the source file name, the source file line number, and the function or method name. The first location is the place where the exception was thrown while the following locations are traceback informations collected by catching, tracing and rethrowing the exception.
BpsExceptions integrate seamless with script exceptions, so that exceptions thrown by c++ can be catched as Error objects by script code, and vice versa.
BpsException::BpsException | ( | ) |
Default constructor for the BpsException objects.
The severity is set to Error.
BpsException::BpsException | ( | const BpsException & | aException | ) |
Copy constructor for the BpsException objects.
aException | Reference of the BpsException object to copy. |
BpsException::BpsException | ( | const QString & | aFilename, |
quint32 | aLinenumber, | ||
const QString & | aFunction, | ||
const QString & | aMessage, | ||
Severity | aSeverity | ||
) |
Standard constructor for the BpsException objects.
This is the most used constructor variant in applications. Typical usage in throwing exceptions as:
For better convenience use the bpsMakeException macro:
aFilename | Source file name, most often provided by FILE macro. |
aLinenumber | Source file line number, most often provided by LINE macro. |
aFunction | Function name, most often provided by FUNCTION macro. |
aMessage | The error message. |
aSeverity | The error severity. |
BpsException::BpsException | ( | const QScriptValue & | aException, |
const QString & | aFilename = QString() |
||
) |
Constructor from QtScript exceptions.
aException | Reference of the exception to copy. |
aFilename | Source file name if known. Will be used if script value has no file info. |
BpsException& BpsException::addLocation | ( | const QString & | aFilename, |
quint32 | aLinenumber, | ||
const QString & | aFunction | ||
) |
Add another location to an existing exception.
Typically used in catch blocks:
For better convenience use the macro bpsTraceException instead:
aFilename | Source file name, most often provided by FILE macro. |
aLinenumber | Source file line number, most often provided by LINE macro. |
aFunction | Function name, most often provided by FUNCTION macro. |
BpsException& BpsException::appendMessage | ( | const QString & | aText | ) |
Append text to the error message of the exception.
aText | The text to append to the message. |
QString BpsException::message | ( | ) | const |
Get the plain message, without location trace information.
BpsException& BpsException::setMessage | ( | const QString & | aMessage | ) |
Set the error message for the exception.
aMessage | The new error message. |
BpsException& BpsException::setSeverity | ( | Severity | aSeverity | ) |
Set the error severity for the exception.
aSeverity | The new error severity. |
Severity BpsException::severity | ( | ) | const |
Get severity.
QString BpsException::text | ( | int | aMaxLocs = 1 | ) | const |
Get the message, along with a log of the locations stack.
aMaxLocs | The maximum number of locations to list. |
QScriptValue BpsException::throwScriptError | ( | QScriptContext * | aContext | ) | const |
Throw a script error of the exception.
This is useful in c++ code that was called from a script, for example in classes derived from QScriptable.
aContext | Pointer to the script context. |
|
related |
Convenience macro to create a BpsException with severity of Error.
aMessage | The error message. |
|
related |
Convenience macro to create a BpsException with severity of Fatal.
aMessage | The error message. |
|
related |
Convenience macro to create a BpsException with severity of Info.
aMessage | The error message. |
|
related |
Convenience macro to create a BpsException with severity of Warning.
aMessage | The error message. |
|
related |
Convenience macro to add a location to the traceback stack.
aException | The exception to add current location to. |