Alex Rivera | Logout

How to build a C++ Dll wrapper that catches all exceptions?

Asked 2009-02-12T13:35:01.470
15

Like the title says, we’re looking for a way to catch all exceptions from a piece of C++ code, and wrap this in a dll. This way we can shield of the application that uses this dll, from any errors occurring in this dll.

However, this does not seem possible with C++ under Windows.

Example:

void function()
{  
    try  
    {    
        std::list<int>::iterator fd_it;
        fd_it++;  
    } catch(...) {}
}

The exception that occurs is not caught by the standard C++ try/catch block, nor by any SEH translator function set by _set_se_translator(). Instead, the DLL crashes, and the program that uses the DLL is aborted. We compiled with Visual C++ 2005, with the option /SHa. Does anyone know if it’s possible in C++/Win32 to catch these kind of problems and make a rocksolid DLL wrapper?

Edit
Report

3 Answers

4

Konrad Rudolph: Of course this code contains a "logic error", it's to illustrate a problem that could occur. Like the man says he wants to be able to shield his dll from any possible errors. You don't think this is a legitimate question? Heard of vendor products. Some of us live in the real world and live with real problems. It's just not possible to fix everyone else's problems

answered 2010-03-12T07:05:54.527
3

Incrementing an iterator on a standard libary container will never throw a C++ exception. It may give you undefined behaviour.

answered 2009-02-12T13:39:33.360
2

This code contains a logic error, if at all. Since a logic error constitues a bug, don't swallow the exception – fix the error!

Of course, this is specific to the particular code. Others have offered more general advice. However, I've found that a lot of people actually do prefer catching exceptions over fixing logic errors and this is simply unacceptable.

answered 2009-02-12T18:59:01.970

Your Answer