欢迎来到天天文库
浏览记录
ID:48042272
大小:272.00 KB
页数:24页
时间:2020-01-13
《Exception.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter10Exception10-2ExceptionsExceptionhandlingisanimportantaspectofobject-orienteddesignChapter10focuseson:thepurposeofexceptionsexceptionmessagesthetry-catchstatementpropagatingexceptionstheexceptionclasshierarchy10-3OutlineExceptionHandlingThetry-catchStatementExceptionClasses10-4Exce
2、ptionsAnexceptionisanobjectthatdescribesanunusualorerroneoussituationExceptionsarethrownbyaprogram,andmaybecaughtandhandledbyanotherpartoftheprogramAprogramcanbeseparatedintoanormalexecutionflowandanexceptionexecutionflowAnerrorisalsorepresentedasanobjectinJava,butusuallyrepresentsaunrecov
3、erablesituationandshouldnotbecaught10-5ExceptionHandlingJavahasapredefinedsetofexceptionsanderrorsthatcanoccurduringexecutionAprogramcandealwithanexceptioninoneofthreeways:ignoreithandleitwhereitoccurshandleitananotherplaceintheprogramThemannerinwhichanexceptionisprocessedisanimportantdesi
4、gnconsideration10-6ExceptionHandlingIfanexceptionisignoredbytheprogram,theprogramwillterminateabnormallyandproduceanappropriatemessageThemessageincludesacallstacktracethat:indicatesthelineonwhichtheexceptionoccurredshowsthemethodcalltrailthatleadtotheattemptedexecutionoftheoffendinglineSee
5、Zero.java10-7OutlineExceptionHandlingThetry-catchStatementExceptionClasses10-8ThetryStatementTohandleanexceptioninaprogram,thelinethatthrowstheexceptionisexecutedwithinatryblockAtryblockisfollowedbyoneormorecatchclausesEachcatchclausehasanassociatedexceptiontypeandiscalledanexceptionhandle
6、rWhenanexceptionoccurs,processingcontinuesatthefirstcatchclausethatmatchestheexceptiontypeSeeProductCodes.java10-9ThefinallyClauseAtrystatementcanhaveanoptionalclausefollowingthecatchclauses,designatedbythereservedwordfinallyThestatementsinthefinallyclausealwaysareexecutedIfnoexceptionisge
7、nerated,thestatementsinthefinallyclauseareexecutedafterthestatementsinthetryblockcompleteIfanexceptionisgenerated,thestatementsinthefinallyclauseareexecutedafterthestatementsintheappropriatecatchclausecomplete10-10ExceptionPropagationAnexceptioncanbehandledata
此文档下载收益归作者所有