I'm facing strange problem. Namely, Qt somehow turns off exception handling in my program. I can't catch any exception, and when I throw an exception application crashes.

I'm using Qt 4.7.0 (32 bit) from Qt SDK v2010.05 on Windows 7 (64 bit), g++ (GCC) 4.5.1 from MinGW, NetBeans 6.9.1. But I also cheked this with g++ 3.4.5 (also from MinGW) and Qt Creator 2.0.1 - same strange behavior.

For example (simplest case):

#include <Qt/QApplication.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>

using namespace std;


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

    try {
        cout << "Before exception" << endl;
        throw runtime_error("Exception occured");
        cout << "After exception" << endl;
    } catch (runtime_error& exc) {
        cout << exc.what() << endl;
        exit(1);
    }

    return 0;
}

When I execute above program I've got this output:

Before exception

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

I've tried to add flag "-fexceptions" to g++ but it hasn't changed anything.

When I don't use Qt, everything is OK:

#include <Qt/QApplication.h> // It is not caused only by including Qt header
                             // so it doesn't matter if I comment this out or not
#include <iostream>
#include <stdexcept>
#include <cstdlib>

using namespace std;


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

    try {
        cout << "Before exception" << endl;
        throw runtime_error("Exception occured");
        cout << "After exception" << endl;
    } catch (runtime_error& exc) {
        cout << exc.what() << endl;
        
Edit
Report