c++exceptionsandboxerror-recovery

Recoverying from exceptions


In our application (c++) we load 3rd party DLLs using LoadLibrary. Sometimes these DLLs cause exceptions, such as "Access violation reading location 0x00000000..".

Is it possible to recover from such an exception, for example using try & catch or some other mechanism? in other world, is that possible to create a sandbox within the same process that withstand such events?

Thank you


Solution

  • You could try a different type of exception handler:

    __try
    {
        // Code that might cause an access violation goes here. 
    
    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        int code = _exception_code();
    
    }
    

    Beware though, such handlers can't be used in any routine where C++ objects need stack unwinding as the compiler will warn you (irritatingly).