Dave's Brain

Browse - Programming Tips - How do I do catch exceptions that are being thrown by a DLL

Date: 2008jul31
Keywords: CxxThrowException
OS: Windows
Platform: win32
Language: C/C++

Q.  How do I do catch exceptions that are being thrown by a DLL
I don't have the source for?

A.  Use SetUnhandledExceptionFilter() like this...

static void RestartClientProgram() { char szClient[MAX_PATH+1]; GetModuleFileName(NULL, szClient, sizeof(szClient)); printf("Restarting %s\n", szClient); WinExec(szClient, SW_NORMAL); _exit(1); // Don't use exit() since may be trapped } static LONG WINAPI MyUnHandleExceptionFilter(struct _EXCEPTION_POINTERS *lpExceptionInfo) { int code; code = lpExceptionInfo->ExceptionRecord->ExceptionCode; printf("Exception code=0x%x\n", code); RestartClientProgram(); return EXCEPTION_EXECUTE_HANDLER; // Terminate probably } void ExampleUse() { SetUnhandledExceptionFilter(MyUnHandleExceptionFilter); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.