danvratil / qcoro

C++ Coroutines for Qt
https://qcoro.dvratil.cz
MIT License
331 stars 53 forks source link

QCoro::waitFor does not rethrow exceptions #172

Closed cvuchener closed 1 year ago

cvuchener commented 1 year ago

Using a9c69b9225832e7706296b002341ced094eb5e73

#include <QCoreApplication>
#include <QCoroTask>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    auto task = []() -> QCoro::Task<> { 
        throw std::runtime_error("error");
        co_return;
    }();
    try {
        QCoro::waitFor(task);
        qInfo() << "Everything is fine";
    }
    catch (std::exception &e) {
        qInfo() << "Something went wrong:" << e.what();
    }
    return 0;
}

When the exception is thrown, QCoro::waitFor blocks forever instead of rethrowing the exception.