C

QSafeExceptionHandler Class

class SafeRenderer::QSafeExceptionHandler

QSafeExceptionHandler is a proxy class to deliver or throw exceptions. More...

Header: #include <QSafeExceptionHandler>
Since: QtSafeRenderer 3.0

Static Public Members

void handleException(const T &exception)
void installExceptionHandler(SafeRenderer::QSafeExceptionHandlerInterface *exceptionHandlerInterface)

Detailed Description

Exception handler base class that can be called to throw an exception, let the user handle the exception through exception handler or call std::abort if exceptions are disabled.

Member Function Documentation

[static] template <typename T> void QSafeExceptionHandler::handleException(const T &exception)

Static function to determine what to do with given exception. If QT_NO_EXCEPTIONS std::abort will be called.

Default behavior is to throw the given exception.

Type of the argument needs to be SafeRenderer::QSafeException or derived from it.

[static] void QSafeExceptionHandler::installExceptionHandler(SafeRenderer::QSafeExceptionHandlerInterface *exceptionHandlerInterface)

Install a filter class exceptionHandlerInterface which is called for each incoming SafeRenderer::QSafeException.

This exception handler allows the user / system to add needed logging and tear-down logic before system is shut down / rebooted. In case the system does not support exceptions, exception handler can be used in combination with defining QT_NO_EXCEPTIONS flag. In that case std::abort is called after user logic is done handling the said exception.

Example of an exception handler that catches only SafeRenderer::QSafeFileExceptions for specific handling before passing the control back to QSR Runtime:

// Our main class can inherit the QSafeExceptionHandlerInterface and so can be installed
// as an exception handler.
class SafeSystem : public SafeRenderer::QSafeExceptionHandlerInterface {
public:
    virtual void onException(const SafeRenderer::QSafeException &exception) {
        // Only handle FileExceptions, let SafeRenderer handle everything else.
        if (exception.type() == SafeRenderer::QSafeException::ExceptionType::FileException) {
            // Log the file exception.
            std::cerr << "File exception caught: " << exception.what();

            // Any other logic for handling file exceptions / teardown...
        }
    }
};

int main(int argc, char *argv[])
{
    Q_UNUSED(argc);
    Q_UNUSED(argv);

    // Create instance of our system.
    SafeSystem system;

    // Install the system as our exception handler. Now all exceptions will pass through
    // our system's onException() function and can be intercepted or let fall through.
    SafeRenderer::QSafeExceptionHandler::installExceptionHandler(&system);

    // Rest of the QSR initialization...
}

Available under certain Qt licenses.
Find out more.