News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

No exception handling with MinGW compiler but with MSVC compiler it works.

Started by acinfo64, September 03, 2008, 10:05:43 AM

Previous topic - Next topic

acinfo64

Dear All,

I'm using C::B and installed it with the installer incl MinGW.  In my code (which is a wxWidgets GUI app without DLL's) I use the exception handling with try and catch.


try
{
       
}
catch(const std::exception& ex)
{
    std::cout << "Exception caught: " << ex.what() << std::endl;
}


When I compile the program with MinGW and run it the program crashes without throwing any exception.

However when I compile the same program by changing the GCC compiler to MSVC compiler in C::B the program works fine and throws the exception.  It also works under C::B and GCC in Linux.

My question is: Is this a bug in C::B or MinGW or are there settings not correct and how to solve this? I have played with the -fexceptions without success.

I saw some problems with MinGW but I understood that it was only causing problems when using DLL's and I don't use them.


thomas

Since exceptions work just fine for me, I think it may have to do with your wxWidgets build. Did you for example build wxWidgets with MSVC and then link that with a program compiled in MinGW?
The two have different exception models, so that might be one possible reason.

To narrow down the field, you might want to try a "hello world" exception program, i.e. one without wxWidgets. If that doesn't work either, something's broken. If that works, you know where to look.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

acinfo64

Thanks for your reaction.

I did the following test. In C::B I made a new console appication with the GCC compiler as compiler settings and with the following test code:


#include <iostream>
using namespace std;

int main()
{

    try
    {
        throw "Memory allocation failure!";
    }

    catch(char* strg)
    {
        cout<<"Testing Exceptions: "<<strg<<endl;
    }

    cout << endl << endl << endl <<"ENDING PROGRAM"<<endl;

}


Then the console window shows see image mingw.jpg in the attachment.

When I then only change the compiler to MSVC compiler and nothing else I get see image MSVC.jpg in the attachment.

So with the most minimum application it is still not working.

[attachment deleted by admin]

thomas

That snippet works just fine for me (as expected, it has to work!).

It can't be that you accidentially turned off exception handling (-fno-exceptions), because the compile would then abort with an error on the throw keyword. Same if you accidentially compiled C instead of C++.

So well... compiler install is somehow screwed up, only idea I have really.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."