En esta página

QException Class

La clase QException constituye una clase base para las excepciones que pueden transmitirse entre subprocesos. Más información...

Encabezado: #include <QException>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Heredado por:

QUnhandledException

Funciones públicas

QException()
QException(const QException &other)
virtual ~QException()
virtual QException *clone() const
virtual void raise() const
QException &operator=(const QException &other)

Descripción detallada

Qt Concurrent admite lanzar y capturar excepciones entre hilos, siempre que la excepción herede de QException e implemente dos funciones auxiliares:

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

Las subclases de QException deben lanzarse por valor y capturarse por referencia:

try  {
    QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException
} catch (MyException &e) {
    // handle exception
}

Si se lanza una excepción que no sea una subclase de QException, las Qt Concurrent funciones lanzarán una excepción « QUnhandledException » en el hilo receptor.

Al utilizar ` QFuture`, las excepciones transferidas se lanzarán al llamar a las siguientes funciones:

Documentación de las funciones de miembro

[noexcept default] QException::QException()

Crea un objeto QException.

[constexpr noexcept default] QException::QException(const QException &other)

Crea una copia de other.

Nota: Ten cuidado al utilizar esta función, ya que corres el riesgo de realizar un «slicing».

Véase también clone().

[virtual noexcept] QException::~QException()

Elimina este objeto de tipo « QException ».

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

En tu subclase ` QException `, vuelve a implementar el método `clone()` de la siguiente manera:

MyException *MyException::clone() const { return new MyException(*this); }

[virtual] void QException::raise() const

En tu subclase ` QException `, vuelve a implementar el método `raise()` de la siguiente manera:

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

[noexcept default] QException &QException::operator=(const QException &other)

Asigna por copia other sobre este objeto.

Nota: Ten cuidado al utilizar esta función, ya que corres el riesgo de realizar un «slicing».

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.