📄 log.h
字号:
// Log.h : header file for Exception Handling Functionality
//
#ifndef _LOG_H
#define _LOG_H
/////////////////////////////////////////////////////////////////////////////
// Ensure we have necessary includes for supported Exceptions.
/////////////////////////////////////////////////////////////////////////////
#ifndef __AFXWIN_H__ // CException CArchiveException CFileException
#include <afxwin.h> // CSimpleException CMemoryException CNotSupportedException
#endif // CResourceException CUserException
// Other MFC Exceptions are included in LOG.CPP so as to
// have minimal impact on your existing application
#if _MSC_VER >= 1100 // VC 5.0 specific -- support for
#include <comdef.h> // #import and _com_error exception class
#endif
/////////////////////////////////////////////////////////////////////////////
// Misc. Functions/Class Declarations
/////////////////////////////////////////////////////////////////////////////
// Crack HRESULT into error message
extern CString LogCrackHR( HRESULT hr );
// Initialize Exception Handling
extern void LogEnable( BOOL bLogVerbose );
// Dump contents of all exceptions logged.
extern void LogDisplay( void );
extern void LogDisplay( CListBox &mListBox, BOOL bReset = FALSE );
// Reset list of Exceptions
extern void LogReset( void );
extern BOOL LogSaveToFile( LPCTSTR lpszFileName );
// Class for Win32 Structured Exception Handling
class SEH_Exception {
private:
unsigned int m_uSECode;
public:
SEH_Exception(unsigned int uSECode) : m_uSECode(uSECode) {}
SEH_Exception() {}
~SEH_Exception() {}
unsigned int getSeHNumber() { return m_uSECode; }
};
/////////////////////////////////////////////////////////////////////////////
// Exception Logging Functions -- The File/Date/Time version(s)
/////////////////////////////////////////////////////////////////////////////
// Used to store each line of text from LogException() functions
extern void Log( LPCTSTR lpszFormat, ... ); // Message Format String
// Crack open and log details of different types of exceptions
extern void LogException( CException *e, // MFC Exception
LPCSTR lpszTimeStamp, // Date & Time
LPCSTR lpszFile, // File Name
int nLine ); // Line #
extern void LogException( SEH_Exception &e, // Win32 SEH Class
LPCSTR lpszTimeStamp, // Date & Time
LPCSTR lpszFile, // File Name
int nLine ); // Line #
#if _MSC_VER >= 1100
extern void LogException( _com_error &e, // #import excep class
LPCSTR lpszTimeStamp, // Date & Time
LPCSTR lpszFile, // File Name
int nLine ); // Line #
#endif
extern void LogException( LPCSTR lpszTimeStamp, // Date & Time
LPCSTR lpszFile, // File Name
int nLine ); // Line #
/////////////////////////////////////////////////////////////////////////////
// Exception Logging Functions -- Just log the exception, ma'am
/////////////////////////////////////////////////////////////////////////////
// Crack open and log details of different types of exceptions
extern void LogException( CException *e ); // MFC Exception
extern void LogException( SEH_Exception &e ); // Win32 SEH Class
extern void LogException( ); // Unhandled excep
#if _MSC_VER >= 1100
extern void LogException( _com_error &e ); // #import excep class
#endif
/////////////////////////////////////////////////////////////////////////////
// Exception Trapping Macros (3 flavors for 2 versions of the product)
//
// There are 3 flavors of exception trapping macro given below. One version
// of these is specific to VC 4.X, i.e. no support for _com_error, the
// second for VC 5.0 or greater, i.e. support for _com_error.
//
// LOGQ -- Quiet trapping of rexceptions. No logging of messages, but
// sets a Boolean value (bRetVal) to FALSE to indicate exception
// occured. This means your function needs:
// BOOL bRetVal = TRUE;
// to use this macro.
// LOGE -- Catches exception, deciphers it and logs it.
// LOGR -- Catches exception, deciphers it, logs it, and sets a Boolean
// value (bRetVal) to FALSE to indicate exception occured. This
// means your function needs:
// BOOL bRetVal = TRUE;
// to use this macro.
/////////////////////////////////////////////////////////////////////////////
// VC 4.X version(s)
#if _MSC_VER < 1100
// The quiet version, no logging, just catch the exception
#define LOGQ( f ) try \
{ \
f; \
} \
catch( CException *e) \
{ \
e->Delete(); \
} \
catch( SEH_Exception ) \
{ \
} \
catch(...) \
{ \
}
// The logging version, but still quietly catches the exception
#define LOGE( f ) try \
{ \
f; \
} \
catch( CException *e ) \
{ \
LogException( e, \
__TIMESTAMP__, \
__FILE__, \
__LINE__ );\
} \
catch( SEH_Exception &e ) \
{ \
LogException( e, \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -