📄 exceptionmgr.h
字号:
//
// FILE: ExceptionMgr.h
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////
#ifndef __ExceptionMgr__
#define __ExceptionMgr__
#include <CMclGlobal.h>
#include <CMclAutoLock.h>
#include <CMclLinkedLists.h>
#include <CMclCritSec.h>
#include <CMclEvent.h>
class CExceptionManager;
// Derive your thread object's from CExceptionHandler in order
// to receive notifications of exception in other threads.
//
class CExceptionHandler
{
public:
enum NOTIFICATION_CONTEXT
{
THREAD_EXCEPTION,
// A thread call CExceptionManager::NotifyException.
UNHANDLED_EXCEPTION
// The CExceptionManager caught an unhandled exception
// for the process.
};
public:
// The OnException function will be called by the CExceptionManager
// for this process when (1) an unhandled exception occurs or (2) a
// thread calls the CExceptionManager::NotifyException function to
// broadcast an FYI to interested threads that an exception has
// occurred
// This function will be called in the context of the thread calling
// NotifyException (case 1) or the thread that the exception occurred
// in (case 2).
//
virtual void OnException(
NOTIFICATION_CONTEXT Context,
DWORD dwExceptionCode
) = 0;
};
class CExceptionManager
{
public:
CExceptionManager();
~CExceptionManager();
// RegisterHandler is called to register interested in
// exceptions occurring in other threads. This function
// must be called in the context of the the thread that
// is registering the handler.
//
virtual BOOL RegisterHandler( CExceptionHandler *pHandler );
// UnregisterHandler removes the caller from the list of
// registered handlers. As with RegisterHandler, this
// thread must be called within the context of the thread
// that registered the handler.
//
virtual void UnregisterHandler( CExceptionHandler *pHandler );
// NotifyException is called to inform other threads of the
// exception. This function can be called by any thread to
// broadcast a notification to currently registered exception
// handlers that an exception is about to result in process
// termination.
//
void NotifyException( DWORD dwExceptionCode );
private:
// An unhandled exception filter is installed so that
// registered handlers can learn about other exceptions that
// occurred in the process that were not handled by threads
// that chose to call NotifyException.
//
static LONG WINAPI UnhandledExceptionFilter( PEXCEPTION_POINTERS pExceptionInfo );
void NotifyHandlers(
CExceptionHandler::NOTIFICATION_CONTEXT Context,
DWORD dwExceptionCode
);
typedef BOOL (* PHANDLER_ITERATOR)(
CExceptionHandler *pHandler,
DWORD dwArg1,
DWORD dwArg2,
DWORD dwARg3
);
void ForEachHandler(
PHANDLER_ITERATOR pfxnIterator,
DWORD dwArg1 = 0,
DWORD dwArg2 = 0,
DWORD dwArg3 = 0
);
static BOOL RemoveHandler(
CExceptionHandler *pHandler,
DWORD dwArg1,
DWORD dwArg2,
DWORD dwArg3
);
static BOOL NotifyHandler(
CExceptionHandler *pHandler,
DWORD dwArg1,
DWORD dwArg2,
DWORD dwArg3
);
protected:
// NotifyExceptionHandler is a pure virtual function that must be supplied
// by a derived class. Everything else is taken care of by this base class
// except the actual notification process.
//
virtual void NotifyExceptionHandler(
CExceptionHandler *pHandler,
CExceptionHandler::NOTIFICATION_CONTEXT Context,
DWORD dwExceptionCode
) = 0;
private:
static CMclCritSec s_CritSec;
static CExceptionManager *s_pThis;
CMclLinkedList<CExceptionHandler *> m_RegisteredHandlers;
LPTOP_LEVEL_EXCEPTION_FILTER m_pfxnPrevUnhandledExceptionFilter;
};
#endif // __ExceptionMgr__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -