ExampleFive.cpp
上传用户:skywee
上传日期:2021-12-09
资源大小:141k
文件大小:1k
- #include <afx.h>
- #include <afxdb.h>
- void Func2()
- {
- TRY
- {
- printf("raising memory exceptionn");
- AfxThrowMemoryException();
- printf("this line should never appearn");
- }
- CATCH(CException ,pe)//!!!注意,抛出的是对象的指针
- {
- printf("caught generic exception; rethrowingn");
- THROW_LAST(); //重新抛出必须用THROW_LAST();而不是THROW()
- printf("this line should never appearn");
- }
- END_CATCH
- printf("this line should never appearn");
- }
- void Func3()
- {
- TRY
- {
- Func2();
- printf("this line should never appearn");
- }
- CATCH(CFileException,pe)
- {
- printf("caught file exceptionn");
- }
- AND_CATCH(CMemoryException,pe)
- {
- printf("caught memory exceptionn");
- }
- AND_CATCH(CException,pe) //捕获剩下的MFC异常类对象
- {
- printf("caught generic exceptionn");
- pe->ReportError();
- }
- END_CATCH
- }
- int main()
- {
- AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
- Func3();
- return 0;
- }