Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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 ()=default
 Constructs a QException object.
 
 ~QException () noexcept
 Destroys this QException object.
 
 QException (const QException &)=default
 Creates a copy of other.
 
QExceptionoperator= (const QException &)=default
 Copy-assigns other over this object.
 
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() [1/2]

QException::QException ( )
default

Constructs a QException object.

◆ ~QException()

QException::~QException ( )
noexcept

Destroys this QException object.

Definition at line 88 of file qexception.cpp.

◆ QException() [2/2]

QException::QException ( const QException & other)
default

Creates a copy of other.

Note
Be careful when using this function, as you risk slicing.
See also
clone()

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, MyException, and QUnhandledException.

Definition at line 122 of file qexception.cpp.

◆ operator=()

QException & QException::operator= ( const QException & other)
default

Copy-assigns other over this object.

Note
Be careful when using this function, as you risk slicing.

◆ raise()

void QException::raise ( ) const
virtual

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

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

Reimplemented in MyException, MyException, and QUnhandledException.

Definition at line 116 of file qexception.cpp.


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