terminate called, but shouldn't be

Given this program:

#include <stdexcept>
#include <iostream>

using namespace std;

int main() {
  try {
    throw std::runtime_error( "whoops!" );
  }
  catch ( std::exception const &e ) {
    cout << e.what() << endl;
  }
  return 0;
}

and compiled with g++ under cygwin, I get only the output "whoops!" as expected. When compiled with clang++ 3.0 under MinGW, I get:

terminate called after throwing an instance of 'std::runtime_error'
  what(): whoops!

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

Why? terminate should NOT be called since the exception is caught.

- Paul

With ToT clang on darwin it works fine.

-eric

As nice at that is, I also need to have code compile and execute as expected under Windows.

- Paul

I merely don't have a machine to test on. You should try top of tree and see how that goes. If not, you should file a bug and or diagnose what's going on.

-eric

As I understand it, Clang does not implement parts of the Win32/64 ABI needed for exception handling compatibility with the msvc6 C/C++ run-time used by MinGW. See the following link for previous discussion with subject "LLVM/Clang and setjmp/longjmp exception handling on MinGW"

http://www.digipedia.pl/usenet/thread/11413/12904/

Tom.

Then maybe you should try the Cygwin package of clang:

$ clang++ -v -Wall -pedantic -W exc.cc
clang version 3.1 (trunk 146969)
Target: i386-pc-cygwin
Thread model: posix
"/home/csaba/bin/clang" -cc1 -triple i386-pc-cygwin -S -disable-free
-main-file-name exc.cc -mrelocation-model static -mdisable-fp-elim
-mconstructor-aliases -target-cpu pentium4 -target-linker-version
2.22.51.20111013 -momit-leaf-frame-pointer -v -resource-dir
/home/csaba/bin/../lib/clang/3.1 -fmodule-cache-path
/var/tmp/clang-module-cache -Wall -W -pedantic -fdeprecated-macro
-fno-dwarf-directory-asm -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 184 -mstackrealign -fno-use-cxa-atexit -fgnu-runtime
-fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi
-fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o
/cygdrive/c/Users/csaba/AppData/Local/Temp/exc-EQXgtP.s -x c++ exc.cc
clang -cc1 version 3.1 based upon llvm 3.1svn default target i386-pc-cygwin
(snip)

$ ./a.exe
whoops!

Csaba

I just tried this with 3.1 and it works as expected, so it’s time for you to upgrade :slight_smile: