Catching exceptions across shared object boundaries



 DEVELOP > c-Plus-Plus > Catching exceptions across shared object boundaries

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "foxx"
Date: 29 Aug 2006 12:53:53 PM
Object: Catching exceptions across shared object boundaries
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)
.

User: "Jens Theisen"

Title: Re: Catching exceptions across shared object boundaries 29 Aug 2006 04:05:17 PM
foxx wrote:

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!

The following does work:
g++ -fPIC -shared libprint.cc -o libprint.so
I'm not an expert, but I guess you're simply not creating a shared
library (whatever that means technically). -shared is also understood by ld.
Jens
.

User: "Earl Purple"

Title: Re: Catching exceptions across shared object boundaries 30 Aug 2006 07:29:34 AM
foxx wrote:

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!

etc:
1. I'd use a makefile and build the library with -shared
2. Get rid of throw specifications.
.
User: "foxx"

Title: Re: Catching exceptions across shared object boundaries 31 Aug 2006 08:20:27 AM
Thanks guys -- for for reference, I got it working with syntax like
this:
(I'm using cygwin on windows, but compiling without cygwin
dependencies)
---------------Makefile:
libException.dll: Exception.cc
g++ -mno-cygwin -fPIC -shared -o libException.dll Exception.cc
libtest1.dll: test1.cc libException.dll
g++ -mno-cygwin -fPIC -shared -o libException.dll test1.cc
libmymain.dll: mymain.cc libtest1.dll libException.dll
g++ -mno-cygwin -fPIC -shared -o libmymain.dll mymain.cc libtest1.dll
main.exe: libmymain.dll
g++ -mno-cygwin -o main.exe main.cc -L. -ltest1 -lmymain
.


User: "Victor Bazarov"

Title: Re: Catching exceptions across shared object boundaries 29 Aug 2006 01:02:51 PM
foxx wrote:

This is driving me nuts. I can't catch an exception thrown out of a
.so library. [..]

Just to let you know, .so and catching exceptions across them are not
defined by C++, so you might consider asking in the newsgroup for your
OS as well; folks there might be more accustomed to those things, and
have more experience (per newsreader capita) with shared objects.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER