C++基礎(結搆異常)
__try
{
......
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
wprintf(GetExceptionDescribe(GetExceptionCode()));
}
#pragma once
typedef struct tagExcpCode
{
DWORD dwCode;
LPTSTR lpDescribe;
}EXCPCODE,*PEXCPCODE;
EXCPCODE g_excp_table[]=
{
EXCEPTION_ACCESS_VIOLATION,
_T("The thread attempts to read from or write to a virtual address for which it does not have access."),
EXCEPTION_ARRAY_BOUNDS_EXCEEDED,
_T("The thread attempts to access an array element that is out of bounds, and the underlying hardware supports bounds checking."),
EXCEPTION_BREAKPOINT,
_T("A breakpoint is encountered."),
EXCEPTION_DATATYPE_MISALIGNMENT,
_T("The thread attempts to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries, 32-bit values on 4-byte boundaries, and so on."),
EXCEPTION_FLT_DENORMAL_OPERAND,
_T("One of the operands in a floating point operation is denormal. A denormal value is one that is too small to represent as a standard floating point value."),
EXCEPTION_FLT_DIVIDE_BY_ZERO,
_T("The thread attempts to divide a floating point value by a floating point divisor of 0 (zero)."),
EXCEPTION_FLT_INEXACT_RESULT,
_T("The result of a floating point operation cannot be represented exactly as a decimal fraction."),
EXCEPTION_FLT_INVALID_OPERATION,
_T("A floatin point exception that is not included in this list."),
EXCEPTION_FLT_OVERFLOW,
_T("The exponent of a floating point operation is greater than the magnitude allowed by the corresponding type."),
EXCEPTION_FLT_STACK_CHECK,
_T("The stack has overflowed or underflowed, because of a floating point operation."),
EXCEPTION_FLT_UNDERFLOW,
_T("The exponent of a floating point operation is less than the magnitude allowed by the corresponding type."),
EXCEPTION_GUARD_PAGE,
_T("The thread accessed memory allocated with the PAGE_GUARD modifier."),
EXCEPTION_ILLEGAL_INSTRUCTION,
_T("The thread tries to execute an invalid instruction."),
EXCEPTION_IN_PAGE_ERROR,
_T("The thread tries to access a page that is not present, and the system is unable to load the page. For example, this exception might occur if a network connection is lost while running a program over a network."),
EXCEPTION_INT_DIVIDE_BY_ZERO,
_T("The thread attempts to divide an integer value by an integer divisor of 0 (zero)."),
EXCEPTION_INT_OVERFLOW,
_T("The result of an integer operation causes a carry out of the most significant bit of the result."),
EXCEPTION_INVALID_DISPOSITION,
_T("An exception handler returns an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception."),
EXCEPTION_INVALID_HANDLE,
_T("The thread used a handle to a kernel object that was invalid (probably because it had been closed.)"),
EXCEPTION_NONCONTINUABLE_EXCEPTION,
_T("The thread attempts to continue execution after a non-continuable exception occurs."),
EXCEPTION_PRIV_INSTRUCTION,
_T("The thread attempts to execute an instruction with an operation that is not allowed in the current computer mode."),
EXCEPTION_SINGLE_STEP,
_T("A trace trap or other single instruction mechanism signals that one instruction is executed."),
EXCEPTION_STACK_OVERFLOW,
_T("The thread uses up its stack."),
};
int g_excp_tableCount = sizeof(g_excp_table)/sizeof(g_excp_table[0]);
LPTSTR GetExceptionDescribe(DWORD dwCode)
{
for (int i=0;i
0條評論