I made a subclass of QException as follows:
#include <QtConcurrent>
#include <QException>
class ProcessingException : public QException
{
public:
ProcessingException(QString const& message) :
message(message)
{}
virtual ~ProcessingException()
{
}
void raise() const { throw *this; }
ProcessingException *clone() const { return new ProcessingException(*this); }
QString getMessage() const
{
return message;
}
private:
QString message;
};
From a method that's run by QtConcurrent::run I throw an instance of this subclass with throw new ProcessingException("test");
. Then if I understand the documentation properly, when I collect the future's result with .waitForFinished()
, Qt should re-throw the QException subclass. However, using this approach I'm only able to catch a QUnhandledException:
try
{
watcher->waitForFinished();
}
catch(const ProcessingException &e)
{
qCritical() << "Caught:" << e.getMessage();
}
catch(const QUnhandledException &e)
{
qCritical() << "Uncaught qexception!";
}
What am I missing?