boostorg / thread

Boost.org thread module
http://boost.org/libs/thread
201 stars 161 forks source link

boost::future handles std::exception differently from std::future on Windows #325

Open sinall opened 4 years ago

sinall commented 4 years ago

I'm using VC++2019, I use boost::when_all since std::when_all is not available yet. But I find that boost::async will discard std::exception::what() and use 'Unknown exception' or 'std::exception' instead, on the other hand, std::async could handle the message as expected.

#include <iostream>

#define BOOST_THREAD_PROVIDES_FUTURE
#include <boost/thread/future.hpp>

#include <future>

int main() {
    auto f1 = boost::async([]{ // the program will print 'my exception' if this line uses 'std::async'.
        try{
            throw std::invalid_argument("my exception");
        }
        catch (const std::exception& e) {
            throw e;
        }
    });

    try {
        f1.get();
    }
    catch (const std::exception& e) {
        std::cout << e.what() << std::endl;
    }
}