Hi all - first, a little test program, test.cpp:
----
#include <iostream>
#include <stdexcept>
int main(int argc, char* argv[])
{
using namespace std;
try
{
throw runtime_error("runtime_error");
}
catch (const std::runtime_error& re)
{
cout << "Caught runtime_error: " << re.what() << endl;
}
return 0;
}
----
When I compile this with my XCode g++ (gcc version 4.2.1 (Apple Inc.
build 5659)) , it works as expected:
$ /usr/bin/g++ -o test test.cpp
$ otool -L ./test
./test:
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0,
current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
current version 125.0.1)
$ ./test
Caught runtime_error: runtime_error
However, with my gentoo-alt gcc-apple g++ (gcc version 4.2.1 (Gentoo
4.2.1_p5659, Apple Inc. build 5659):
$ g++ -o test test.cpp
$ otool -L ./test
./test:
/Users/mattm/gentoo/usr/lib/gcc/x86_64-apple-darwin10/4.2.1/libstdc++.6.dylib
(compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
current version 125.0.1)
$ ./test
terminate called after throwing an instance of 'std::runtime_error'
Abort trap
I've tried a few flags (-fexceptions, etc.), but I still can't get any
C++ code compiled with the gentoo-alt gcc-apple to catch exceptions
properly. Any ideas?
Matt.