Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QException Class Reference

\inmodule QtCore More...

#include <qexception.h>

+ Inheritance diagram for QException:
+ Collaboration diagram for QException:

Public Member Functions

 ~QException () noexcept
 
virtual void raise () const
 In your QException subclass, reimplement raise() like this:
 
virtual QExceptionclone () const
 In your QException subclass, reimplement clone() like this:
 

Detailed Description

\inmodule QtCore

The QException class provides a base class for exceptions that can be transferred across threads.

Since
5.0

Qt Concurrent supports throwing and catching exceptions across thread boundaries, provided that the exception inherits from QException and implements two helper functions:

class MyException : public QException
{
public:
void raise() const override { throw *this; }
MyException *clone() const override { return new MyException(*this); }
};

QException subclasses must be thrown by value and caught by reference:

try {
QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException
} catch (MyException &e) {
// handle exception
}

If you throw an exception that is not a subclass of QException, the \l{Qt Concurrent} functions will throw a QUnhandledException in the receiver thread.

When using QFuture, transferred exceptions will be thrown when calling the following functions: \list

Definition at line 21 of file qexception.h.

Constructor & Destructor Documentation

◆ ~QException()

QException::~QException ( )
noexcept

Definition at line 85 of file qexception.cpp.

Member Function Documentation

◆ clone()

QException * QException::clone ( ) const
virtual

In your QException subclass, reimplement clone() like this:

MyException *MyException::clone() const { return new MyException(*this); }

Reimplemented in MyException, and QUnhandledException.

Definition at line 95 of file qexception.cpp.

◆ raise()

void QException::raise ( ) const
virtual

In your QException subclass, reimplement raise() like this:

void MyException::raise() const { throw *this; }

Reimplemented in MyException, and QUnhandledException.

Definition at line 89 of file qexception.cpp.

Referenced by QtFuture::makeExceptionalFuture(), QFutureInterfaceBase::reportException(), and QtPrivate::ExceptionStore::setException().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: