Structured Exception Handling 异常扑捉

/* Eval_Exception 输入参数: EXCEPTION 异常代码 返回值: 以下三个中的一个 取决于你准备如何处理 EXCEPTION_EXECUTE_HANDLER EXCEPTION_CONTINUE_SEARCH EXCEPTION_CONTINUE_EXECUTION */ int Eval_Exception (DWORD n_except) { int nRet = EXCEPTION_CONTINUE_SEARCH; //0 switch(n_except) { #define CASE_EXCEPTION(X) case(X):{ TRACE(_T("%s/r/n"), #X); break; } CASE_EXCEPTION( EXCEPTION_ACCESS_VIOLATION );// STATUS_ACCESS_VIOLATION CASE_EXCEPTION( EXCEPTION_DATATYPE_MISALIGNMENT);// STATUS_DATATYPE_MISALIGNMENT CASE_EXCEPTION( EXCEPTION_BREAKPOINT );// STATUS_BREAKPOINT CASE_EXCEPTION( EXCEPTION_SINGLE_STEP );// STATUS_SINGLE_STEP CASE_EXCEPTION( EXCEPTION_ARRAY_BOUNDS_EXCEEDED );// STATUS_ARRAY_BOUNDS_EXCEEDED CASE_EXCEPTION( EXCEPTION_FLT_DENORMAL_OPERAND);// STATUS_FLOAT_DENORMAL_OPERAND CASE_EXCEPTION( EXCEPTION_FLT_DIVIDE_BY_ZERO );// STATUS_FLOAT_DIVIDE_BY_ZERO CASE_EXCEPTION( EXCEPTION_FLT_INEXACT_RESULT );// STATUS_FLOAT_INEXACT_RESULT CASE_EXCEPTION( EXCEPTION_FLT_INVALID_OPERATION );// STATUS_FLOAT_INVALID_OPERATION CASE_EXCEPTION( EXCEPTION_FLT_OVERFLOW );// STATUS_FLOAT_OVERFLOW CASE_EXCEPTION( EXCEPTION_FLT_STACK_CHECK );// STATUS_FLOAT_STACK_CHECK CASE_EXCEPTION( EXCEPTION_FLT_UNDERFLOW );// STATUS_FLOAT_UNDERFLOW CASE_EXCEPTION( EXCEPTION_INT_DIVIDE_BY_ZERO );// STATUS_INTEGER_DIVIDE_BY_ZERO CASE_EXCEPTION( EXCEPTION_INT_OVERFLOW );// STATUS_INTEGER_OVERFLOW CASE_EXCEPTION( EXCEPTION_PRIV_INSTRUCTION );// STATUS_PRIVILEGED_INSTRUCTION CASE_EXCEPTION( EXCEPTION_IN_PAGE_ERROR );// STATUS_IN_PAGE_ERROR CASE_EXCEPTION( EXCEPTION_ILLEGAL_INSTRUCTION );// STATUS_ILLEGAL_INSTRUCTION CASE_EXCEPTION( EXCEPTION_NONCONTINUABLE_EXCEPTION );// STATUS_NONCONTINUABLE_EXCEPTION CASE_EXCEPTION( EXCEPTION_STACK_OVERFLOW );// STATUS_STACK_OVERFLOW CASE_EXCEPTION( EXCEPTION_INVALID_DISPOSITION );// STATUS_INVALID_DISPOSITION CASE_EXCEPTION( EXCEPTION_GUARD_PAGE );// STATUS_GUARD_PAGE_VIOLATION CASE_EXCEPTION( EXCEPTION_INVALID_HANDLE );// STATUS_INVALID_HANDLE CASE_EXCEPTION( CONTROL_C_EXIT );// STATUS_CONTROL_C_EXIT default: { TRACE( _T("UNKNOW EXCEPTION/r/n") ); break; } } nRet = EXCEPTION_EXECUTE_HANDLER;//1 //nRet = EXCEPTION_CONTINUE_EXECUTION;//-1 return nRet; } /* 宏定义测试代码 */ #define TRYRUNCODE(x)/ {/ __try / {/ TRACE(_T("Try to Run code===> %s /r/n"), #x);/ x;/*run code*// }/ __except (Eval_Exception(GetExceptionCode())) / {/ /*Structured Exception Handling*// TRACE(_T("Eval_Exception /r/n"));/ }/ }

 

//测试代码 TRYRUNCODE( *((int*)0) = 0; ); int a=100,b=0; TRYRUNCODE( a=a/b; )

你可能感兴趣的:(Structured Exception Handling 异常扑捉)