Code::Blocks Forums

User forums => Help => Topic started by: acinfo64 on September 03, 2008, 10:05:43 am

Title: No exception handling with MinGW compiler but with MSVC compiler it works.
Post by: acinfo64 on September 03, 2008, 10:05:43 am
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.

Code
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.

Title: Re: No exception handling with MinGW compiler but with MSVC compiler it works.
Post by: thomas on September 03, 2008, 10:20:51 am
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.
Title: Re: No exception handling with MinGW compiler but with MSVC compiler it works.
Post by: acinfo64 on September 03, 2008, 11:14:19 am
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:

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]
Title: Re: No exception handling with MinGW compiler but with MSVC compiler it works.
Post by: thomas on September 03, 2008, 11:25:46 am
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.