QUnhandledException Class

The QUnhandledException class represents an unhandled exception in a Qt Concurrent worker thread. \since 5.0. More...

Header: #include <QUnhandledException>
Inherits: QException

Public Functions

QUnhandledException(int exception = ...)
QUnhandledException(const QUnhandledException &other)
QUnhandledException(QUnhandledException &&other)
int exception() const
void swap(QUnhandledException &other)
QUnhandledException &operator=(const QUnhandledException &other)

Reimplemented Public Functions

virtual QUnhandledException *clone() const override
virtual void raise() const override

Detailed Description

\inmoduleQtCore

If a worker thread throws an exception that is not a subclass of QException, the Qt Concurrent functions will throw a QUnhandledException on the receiver thread side. The information about the actual exception that has been thrown will be saved in the QUnhandledException class and can be obtained using the exception() method. For example, you can process the exception held by QUnhandledException in the following way:

 try {
     auto f = QtConcurrent::run([] { throw MyException {}; });
     // ...
 } catch (const QUnhandledException &e) {
     try {
         if (e.exception())
             std::rethrow_exception(e.exception());
     } catch (const MyException &ex) {
         // Process 'ex'
     }
 }

Inheriting from this class is not supported.

Member Function Documentation

[noexcept] QUnhandledException::QUnhandledException(int exception = ...)

\since6.0

Constructs a new QUnhandledException object. Saves the pointer to the actual exception object if exception is passed.

See also exception().

[noexcept] QUnhandledException::QUnhandledException(const QUnhandledException &other)

Constructs a QUnhandledException object as a copy of other.

[noexcept] QUnhandledException::QUnhandledException(QUnhandledException &&other)

Move-constructs a QUnhandledException, making it point to the same object as other was pointing to.

[override virtual] QUnhandledException *QUnhandledException::clone() const

Reimplements: QException::clone() const.

\internal

int QUnhandledException::exception() const

\since6.0

Returns a pointer to the actual exception that has been saved in this QUnhandledException. Returns a null pointer, if it does not point to an exception object.

[override virtual] void QUnhandledException::raise() const

Reimplements: QException::raise() const.

\internal

[noexcept] void QUnhandledException::swap(QUnhandledException &other)

\since6.0

Swaps this QUnhandledException with other. This function is very fast and never fails.

[noexcept] QUnhandledException &QUnhandledException::operator=(const QUnhandledException &other)

Assigns other to this QUnhandledException object and returns a reference to this QUnhandledException object.