strange problems with C++ exceptions with mingw -


i have encountered strange problems exceptions using mingw , managed cut down following example:

#include <iostream> #include <fstream> #include <cstdlib> using namespace std;  void test(int a) {     if (a < 0) {         throw std::ios_base::failure("a < 0");     } } void test_file(std::string const & fname) {     std::ifstream inf(fname.c_str(), std::fstream::in);     if (!inf) {         cout << "file error -> throwing exception" << endl;         throw ios_base::failure("could not open input file '" + fname + "'");     } }  int main() {     try { test(-5); }     catch(std::exception& e) {         cerr << "exception caught: " << e.what() << " .. continue anyway" <<endl;     }      try { test_file("file-that-does-not-exist"); }     catch(std::exception& e) {         cerr << "exception caught: " << e.what() << endl;         exit(exit_failure);     }     return exit_success; } 

the first exception caught, second 1 not, nice windows error-box informing me application has stopped working :-( full command-line output is:

exception caught: < 0 .. continue anyway
file error -> throwing exception

this application has requested runtime terminate in unusual way. please contact application's support team more information.

the same happen other exceptions (like std::runtime_error).

am doing wrong, or problem somewhere else?

system info: windows 7 x64, latest mingw32 (re-installed yesterday using mingw-get mingw.org).

thanks lot in advance.
michal

fwiw, on xp sp3 mingw:

using built-in specs. target: mingw32 configured with: ../gcc-4.4.0/configure --prefix=/mingw --build=mingw32 --enable-languages=c,ada,c++,fortran,objc,obj-c++ --disable-nls --disable-win32-registry --disable-werror --enable-threads --disable-symvers --enable-cxx-flags='-fno-function-sections -fno-data-sections' --enable-fully-dynamic-string --enable-libgomp --enable-version-specific-runtime-libs --enable-sjlj-exceptions --with-pkgversion='tdm-1 mingw32' --with-bugurl=http://www.tdragon.net/recentgcc/bugs.php thread model: win32 gcc version 4.4.0 (tdm-1 mingw32) 

results in a.exe:

    ntdll.dll => /cygdrive/c/windows/system32/ntdll.dll (0x7c900000)     kernel32.dll => /cygdrive/c/windows/system32/kernel32.dll (0x7c800000)     msvcrt.dll => /cygdrive/c/windows/system32/msvcrt.dll (0x77c10000) 

output

exception caught: < 0 .. continue anyway file error -> throwing exception exception caught: not open input file 'file-that-does-not-exist' 

so soft evidence pointing in direction of

  • library incompatibility
  • environmental differences
  • bug (?) in version of mingw

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -