资源描述:
《结构化异常处理和c++异常处理区别》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、结构化异常处理和C++的异常处理区别结构化异常处理和C++的异常处理区别Windows异常由系统内核代码捕获,然后传递至用户层,多用于非法内存访问、指令错误等,其类型是CPU定义的,参见《X386保护模式编程》。C++异常是C++编译器生成的结构(多在堆栈上),是普通的用户层代码,异常类型由用户自定义。由于Windows异常处理和C++异常处理均使用堆栈展开,在局部堆栈的使用中存在冲突,一般不能混用。__try{}__finally{}不会检查类内析构以及构造等操作但是try()catch()不会存在这样的问题但
2、是C++编译器上的所以异常类型需要你自己定义。__try{......}__except(EXCEPTION_EXECUTE_HANDLER){wprintf(GetExceptionDescribe(GetExceptionCode()));}#pragmaoncetypedefstructtagExcpCode{DWORDdwCode;LPTSTRlpDescribe;}EXCPCODE,*PEXCPCODE;EXCPCODEg_excp_table[]={EXCEPTION_ACCESS_VIOLATION
3、,_T("Thethreadattemptstoreadfromorwritetoavirtualaddressforwhichitdoesnothaveaccess."),EXCEPTION_ARRAY_BOUNDS_EXCEEDED,_T("Thethreadattemptstoaccessanarrayelementthatisoutofbounds,andtheunderlyinghardwaresupportsboundschecking."),EXCEPTION_BREAKPOINT,_T("Abre
4、akpointisencountered."),EXCEPTION_DATATYPE_MISALIGNMENT,_T("Thethreadattemptstoreadorwritedatathatismisalignedonhardwarethatdoesnotprovidealignment.Forexample,16-bitvaluesmustbealignedon2-byteboundaries,32-bitvalueson4-byteboundaries,andsoon."),EXCEPTION_FLT_
5、DENORMAL_OPERAND,_T("Oneoftheoperandsinafloatingpointoperationisdenormal.Adenormalvalueisonethatistoosmalltorepresentasastandardfloatingpointvalue."),EXCEPTION_FLT_DIVIDE_BY_ZERO,_T("Thethreadattemptstodivideafloatingpointvaluebyafloatingpointdivisorof0(zero)
6、."),EXCEPTION_FLT_INEXACT_RESULT,_T("Theresultofafloatingpointoperationcannotberepresentedexactlyasadecimalfraction."),EXCEPTION_FLT_INVALID_OPERATION,_T("Afloatinpointexceptionthatisnotincludedinthislist."),EXCEPTION_FLT_OVERFLOW,_T("Theexponentofafloatingpo
7、intoperationisgreaterthanthemagnitudeallowedbythecorrespondingtype."),EXCEPTION_FLT_STACK_CHECK,_T("Thestackhasoverflowedorunderflowed,becauseofafloatingpointoperation."),EXCEPTION_FLT_UNDERFLOW,_T("Theexponentofafloatingpointoperationislessthanthemagnitudeal
8、lowedbythecorrespondingtype."),EXCEPTION_GUARD_PAGE,_T("ThethreadaccessedmemoryallocatedwiththePAGE_GUARDmodifier."),EXCEPTION_ILLEGAL_INSTRUCTION,_T("Thethreadtriestoexecuteaninvalidinst