C++ProgrammingLecture6AdvancedTopics[C++编程讲座6高级主题(PPT-46)课件.ppt
《C++ProgrammingLecture6AdvancedTopics[C++编程讲座6高级主题(PPT-46)课件.ppt》由会员分享,可在线阅读,更多相关《C++ProgrammingLecture6AdvancedTopics[C++编程讲座6高级主题(PPT-46)课件.ppt(46页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、EE4E. C+ ProgrammingContentsIntroductionAn object oriented approach to exception handlingclass myClasspublic: int readFile(.)doif (!end_of_file)/ read the fileelsereturn 1; while not_end_of_file return number_of_bytes_read;The try-catch model of exception handlingApplicationObject 1Method callError
2、conditiontry clausecatch clauseException handling example#include #include class DivideByZeroException : public exceptionpublic:DivideByZeroException:DivideByZeroException(): exception(Attempted divide by zero) ;double quotient(int num, int den)if (den=0)throw DivideByZeroException();return (double)
3、(num)/den;int main()int number1,number2;double result;cout number1 number2)try result=quotient(number1,number2);cout The quotient is result endl;catch(DivideByZeroException &dzException)cout Exception! dzException.what() endl;cout nEnter two integers : ;return 0;Re-throwing exceptionsmainObject 2Obj
4、ect 1 throws exceptionCalls method ofCalls method ofre-throwhandles exceptionre-throwclass MyClass1 public:MyClass1() void aMethod1()trythrow exception();catch (exception &caughtException)cout Exception thrown in aMethod1 endl;throw;class MyClass2 public:MyClass2() void aMethod2()MyClass1 myObject1;
5、trymyObject1.aMethod1();catch(exception &caughtException)cout Exception re-thrown in aMethod2 endl;throw;int main()MyClass2 myObject2;trymyObject2.aMethod2();catch(exception &caughtException)cout Exception handled in main endl;cout “Program terminates ;return 0;Exception thrown in aMethod1Exception
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ProgrammingLecture6AdvancedTopics C+ 编程 讲座 高级 主题 PPT 46 课件
链接地址:https://www.taowenge.com/p-15182251.html
限制150内