Author Topic: No exception handling with MinGW compiler but with MSVC compiler it works.  (Read 7495 times)

Offline acinfo64

  • Single posting newcomer
  • *
  • Posts: 7
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.

« Last Edit: September 03, 2008, 10:08:08 am by acinfo64 »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: No exception handling with MinGW compiler but with MSVC compiler it works.
« Reply #1 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline acinfo64

  • Single posting newcomer
  • *
  • Posts: 7
Re: No exception handling with MinGW compiler but with MSVC compiler it works.
« Reply #2 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]

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: No exception handling with MinGW compiler but with MSVC compiler it works.
« Reply #3 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."