QException Class
The QException class provides a base class for exceptions that can transferred across threads. More…
| Header | #include <QException> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Inherits | std::exception |
| Inherited by | QUnhandledException |
List of all members, including inherited members
Public Functions
| ~QException() | |
| virtual void | raise() 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
QException::~QException()
Destroys the exception.
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().
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().