Article ID: 198623
Article Last Modified on 1/5/2006
HKEY_LOCAL_MACHINE\Software\Microsoft\Ole IgnoreServerExceptions="Y"When the above key is set, the COM/RPC run time will pass the following exceptions on to the caller (for debug purposes):
LONG MyUnhandledExceptionFilter(EXCEPTION_POINTERS *ExceptionInfo);
#define PJITTry \
__try { \
UINT __oldErrMode = SetErrorMode(0);
#define PJITExcept(x) \
SetErrorMode(__oldErrMode); \
} __except (MyUnhandledExceptionFilter(GetExceptionInformation())) {}
HRESULT MyClass::MyMethod (BSTR bstrName) {
PJITTry {
return MyClass::_MyMethod(bstrName);
}
PJITExcept {}
} Note that if you are using C++ exception handling (try-catch), then you must provide stub functions in a different file that
call the real functions so you can wrap the function call in a try-except block.
class MyDebugClass : public MyClass {
//... lots of methods
virtual HRESULT MyMethod (BSTR bstrName) {
PJITTry {
return MyClass::_MyMethod(bstrName);
}
PJITExcept {}
}
} If you use the STDMETHOD and STDMETHODIMP macros, it may be as easy as undefining and redefining these
macros.
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x400
#endif
#include <windows.h>
#include <tchar.h>
extern "C"
LONG MyUnhandledExceptionFilter(EXCEPTION_POINTERS *ExceptionInfo)
{
__try {
CHAR AeDebuggerCmdLine[MAX_PATH];
if(IsDebuggerPresent()) return EXCEPTION_CONTINUE_SEARCH;
if (0 == GetProfileString(
_T("AeDebug"),
_T("Debugger"),
NULL,
AeDebuggerCmdLine,
sizeof(AeDebuggerCmdLine)-1)
)
{
return EXCEPTION_CONTINUE_SEARCH;
}
BOOL b;
STARTUPINFO si;
PROCESS_INFORMATION pi;
CHAR CmdLine[MAX_PATH];
DWORD Status;
HANDLE hEvent;
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
hEvent= CreateEvent(&sa,TRUE,FALSE,NULL);
ZeroMemory(&si,sizeof(si));
wsprintf(CmdLine,AeDebuggerCmdLine,GetCurrentProcessId(),hEvent);
si.cb = sizeof(si);
si.lpDesktop = _T("Winsta0\\Default");
b = CreateProcess(NULL,CmdLine,0,0,TRUE,0,0,0,&si,&pi);
if ( b && hEvent) {
Status = WaitForSingleObject(hEvent,INFINITE);
return EXCEPTION_CONTINUE_EXECUTION;
}
return EXCEPTION_CONTINUE_SEARCH;
} // end __try
__except (EXCEPTION_EXECUTE_HANDLER)
{
return EXCEPTION_CONTINUE_SEARCH;
}
}
The caveats with this code are:
Additional query words: IgnoreServerExceptions RPC_E_SERVERFAULT
Keywords: kbhowto kbdebug KB198623