Boost logo

Boost Users :

Subject: [Boost-users] Thread and exception
From: Janne Kätevä (jannekat_at_[hidden])
Date: 2008-12-12 00:58:19


Hi

I have noticed that on Ubuntu my code that uses Boost Threads works fine
when I throw exceptions (for example strings) and catch them in the same
thread. But this doesn't seem to work on Windows XP with Mingw gcc
3.4.5. If I throw a exception in thread, the program crashes. Is there
some known problem with Boost Thread and Mingw? I'm using Boost 1.37.

Simple example:

#include <exception>
#include <boost/thread/thread.hpp>

using namespace std;

class callable {
public:
    void run() {
        try {
            cout << "Throwing" << endl;
            throw string("error");
        } catch(string &e) {
            cout << "Error: " << e << endl;
        }
    }

    void operator()() {
        this->run();
    }
};

int main() {
    callable c;
    boost::thread thrd(boost::ref(c));
    thrd.join();
    return 0;
}

Janne


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net