img wxtsmart


发表于2008/9/28 17:54:00  1777人阅读

分类: VC/MFC 源代码 C/C++


__try{} __finally{}不会检查类内析构以及构造等操作
但是try() catch()不会存在这样的问题但是C++编译器上的所以异常类型需要你自己定义。





#pragma once

typedef struct tagExcpCode
 DWORD dwCode;
 LPTSTR lpDescribe;

EXCPCODE g_excp_table[]=
 _T("The thread attempts to read from or write to a virtual address for which it does not have access."),

 _T("The thread attempts to access an array element that is out of bounds, and the underlying hardware supports bounds checking."),

 _T("A breakpoint is encountered."),

 _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."),

 _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."),

 _T("The thread attempts to divide a floating point value by a floating point divisor of 0 (zero)."),

 _T("The result of a floating point operation cannot be represented exactly as a decimal fraction."),

 _T("A floatin point exception that is not included in this list."),

 _T("The exponent of a floating point operation is greater than the magnitude allowed by the corresponding type."),

 _T("The stack has overflowed or underflowed, because of a floating point operation."),

 _T("The exponent of a floating point operation is less than the magnitude allowed by the corresponding type."),

 _T("The thread accessed memory allocated with the PAGE_GUARD modifier."),

 _T("The thread tries to execute an invalid instruction."),

 _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."),

 _T("The thread attempts to divide an integer value by an integer divisor of 0 (zero)."),

 _T("The result of an integer operation causes a carry out of the most significant bit of the result."),

 _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."),

 _T("The thread used a handle to a kernel object that was invalid (probably because it had been closed.)"),

 _T("The thread attempts to continue execution after a non-continuable exception occurs."),

 _T("The thread attempts to execute an instruction with an operation that is not allowed in the current computer mode."),

 _T("A trace trap or other single instruction mechanism signals that one instruction is executed."),

 _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<g_excp_tableCount;i++)
  if (g_excp_table[i].dwCode==dwCode)
   return g_excp_table[i].lpDescribe;
 return _T("Unkown Exception!");

0 0



取 消