This is driving me nuts. I can't catch an exception thrown out of a
..so library. It passes up and terminates the program instead. Here is
the code for the .so and the executabe, the compiler commands, and the
output. Please help, I ahve spent hours and hours on this!
====FILE libprint.c ==============================
#include <stdio.h>
#include <stdexcept>
using namespace std;
int hello() throw (runtime_error)
{
printf("hello world!\n");
throw runtime_error("kjh");
}
===FILE main.c ==================
#include <stdio.h>
#include <string>
#include <stdexcept>
using namespace std;
extern int hello() throw (runtime_error);
int main() {
try {
hello();
}
catch (...) {
printf("caught!\n");
}
}
===== COMMAND LINE ======
pinch.203$ g++ -fPIC -fexceptions -c libprint.c
pinch.204$ ld -G libprint.o -fexceptions -o libprint.so
pinch.205$ g++ main.c -fexceptions -lprint
pinch.206$ ./a.out
hello world!
terminate called after throwing an instance of 'std::runtime_error'
what(): kjh
Abort
(gcc version is 3.4.3)