views:

532

answers:

2

Suppose you are developing a library with classes to be exported through a DLL (on Windows, or similar shared-library like Linux ELF shared libs). Member functions on those classes throw exceptions either from the standard library or library defined exceptions.

It is totally safe to code in DLLs to throw exceptions to the modules that map the address space of the DLL? What are the considerations to be taken when developing software components in shared libs from where exceptions are thrown to client modules?

Thank you very much.

+1  A: 

It is entirely reasonable for your libraries to throw exceptions or allow exceptions to bubble up from the underlying framework. You need to be careful to document this behavior for users of your library, however, so that the consumer of your code can take appropriate actions to handle any exceptions that could be thrown (or are not caught) by your code.

tvanfosson
+2  A: 

I would agree that it's perfectly reasonable to expect exceptions thrown across library boundaries to work fine. However, don't be too surprised if you run into a few glitches. A Google search for "gcc shared object exceptions" (check out groups too) shows a lot of people having a lot of problems over the years. The last time I tried it with gcc (ca 2003), I gave up because it just didn't work for me. Hopefully, things have improved since then.

Dave Ray