ExampleNine.cpp
上传用户:skywee
上传日期:2021-12-09
资源大小:141k
文件大小:1k
- #include <stdio.h>
- #include <excpt.h>
- #include <windows.h>
- int Filter(DWORD dwError,_EXCEPTION_POINTERS *pep)
- {
- //用第一个参数获取ExceptionCode
- if(dwError==EXCEPTION_ACCESS_VIOLATION)
- printf("Exception_Access_Violationn");
- else
- printf("Unknown Error:%dn",dwError);
- //用第二个参数获取ExceptionCode
- printf("Code=%08X, Address=%08Xn",
- pep->ExceptionRecord->ExceptionCode,
- pep->ExceptionRecord->ExceptionAddress);
- return EXCEPTION_EXECUTE_HANDLER;
- }
- int Func()
- {
- int *pi=NULL;
- __try{
- *pi=10;
- //注意,GetExceptionCode()只能在__except()中调用。
- }__except(Filter(GetExceptionCode(),GetExceptionInformation())){
- printf("__except statementn");
- }
- printf("after __except statementn");
- return 0;
- }
- int main(int argc, char* argv[])
- {
- int i=Func();
- return 0;
- }