6.0.0-rc4Source

QException Class

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

Header#include <QException>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Inheritsstd::exception
Inherited byQUnhandledException

List of all members, including inherited members

Public Functions

~QException()
virtual voidraise() const
virtual QException *clone() const

Detailed Description

An exception that has to travel from a worker thread to the thread that waits for it, for example through a QFuture, must be copyable without knowing its dynamic type. Derive from QException and reimplement raise() and clone():

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

An exception that does not derive from QException reaches the waiting thread wrapped in a QUnhandledException.

See also QUnhandledException.

Member Function Documentation

[override] QException::~QException()

Destroys the exception.

[virtual] QException * QException::clone() const

Returns a copy of this exception, allocated with new, of its own type. Reimplement it in every subclass; the default returns a QException.

See also raise().

[virtual] void QException::raise() const

Throws this exception, as an object of its own type. Reimplement it in every subclass so that the exception can be rethrown in another thread; the default throws a QException, which loses the subclass.

See also clone().