QUnhandledException Class | Qt Core | Qt 6.11.1
Description: The QUnhandledException class represents an unhandled exception in a Qt Concurrent worker thread.

- Qt 6.11
- Qt Core
- C++ Classes
- QUnhandledException
- Qt 6.11.1 Reference Documentation

# QUnhandledException Class

The QUnhandledException class represents an unhandled exception in a Qt Concurrent worker thread. More...

Header: | `#include <QUnhandledException>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`
Inherits: | QException

- List of all members, including inherited members

## Public Functions

`(since 6.0)` | QUnhandledException(std::__exception_ptr::exception_ptr exception = nullptr)
| QUnhandledException(const QUnhandledException &other)
| QUnhandledException(QUnhandledException &&other)
`(since 6.0)` std::__exception_ptr::exception_ptr | exception() const
`(since 6.0)` void | swap(QUnhandledException &other)
QUnhandledException & | operator=(const QUnhandledException &other)

## Detailed Description

If a worker thread throws an exception that is not a subclass of QException, the Qt Concurrent functions will throw a QUnhandledException on the receiver thread side. The information about the actual exception that has been thrown will be saved in the QUnhandledException class and can be obtained using the exception() method. For example, you can process the exception held by QUnhandledException in the following way:

     try {
         auto f = QtConcurrent::run([] { throw MyException {}; });
         // ...
     } catch (const QUnhandledException &e) {
         try {
             if (e.exception())
                 std::rethrow_exception(e.exception());
         } catch (const MyException &ex) {
             // Process 'ex'
         }
     }

Inheriting from this class is not supported.

## Member Function Documentation

### `[noexcept, since 6.0]` QUnhandledException::QUnhandledException(std::__exception_ptr::exception_ptr exception = nullptr)

Constructs a new QUnhandledException object. Saves the pointer to the actual exception object if exception is passed.

This function was introduced in Qt 6.0.

See also exception().

### `[noexcept]` QUnhandledException::QUnhandledException(const QUnhandledException &other)

Constructs a QUnhandledException object as a copy of other.

### `[noexcept]` QUnhandledException::QUnhandledException(QUnhandledException &&other)

Move-constructs a QUnhandledException, making it point to the same object as other was pointing to.

### `[since 6.0]` std::__exception_ptr::exception_ptr QUnhandledException::exception() const

Returns a pointer to the actual exception that has been saved in this QUnhandledException. Returns a `null` pointer, if it does not point to an exception object.

This function was introduced in Qt 6.0.

### `[noexcept, since 6.0]` void QUnhandledException::swap(QUnhandledException &other)

Swaps this unhandled exception object with other. This operation is very fast and never fails.

This function was introduced in Qt 6.0.

### `[noexcept]` QUnhandledException &QUnhandledException::operator=(const QUnhandledException &other)

Assigns other to this QUnhandledException object and returns a reference to this QUnhandledException object.