Qt 6.x
The Qt SDK
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); }
};
\inmodule QtCore
Definition qexception.h:22

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

try {
QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException
} catch (MyException &e) {
// handle exception
}
double e
void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
Calls function once for each item in sequence.
QList< int > list
[14]

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); }
MyException * clone() const override
[2]

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; }
void raise() const override
[1]

Reimplemented in MyException, and QUnhandledException.

Definition at line 89 of file qexception.cpp.

References e.

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

+ Here is the caller graph for this function:

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