61Java第08章--1(Java异常)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JavaJavapenggang@mail.hust.edu.cn(Exception)(Exception)12341CifErrnoErrnoCgoto1„:1„openFiles;if(theFilesOpen){determinethelengthofthefile;if(gotTheFileLength){allocatethatmuchmemory;if(gotEnoughMemory){readthefileintomemory;if(readFailed)errorCode=-1;elseerrorCode=-2;}elseerrorCode=-3;}elseerrorCode=-4;}elseerrorCode=-5;1„„„„1JavaJavaExceptionP469,7.1:HelloWorld.javaJava“”(throw)(catch)1„P470,7.2HelloWorldMod.java2Java3try-catch-finallytrythrowscatchfinally////////……2„try„trycatch„catch„catch„catch(finally)„3JavaOOPExceptionhandlingjava.langThrowableJavaErrorExceptionJavaJavathrowthrowscatch3„ErrorJavaErrorJava„ExceptionJavaJava„RuntimeExceptionJava0,3ThrowableErrorRuntimeException3——Throwable„Throwable()„Throwable(Stringmessage)„StringtoString()„„“classname”:“getMessage()”„StringgetMessage()„StringgetLocalizedMessage()„voidprintStackTrace()„voidprintStackTrace(PrintStreams)„voidprintStackTrace(PrintWriters)„ThrowablefillInStackTrace()ThrowableErrorRuntimeException3„1()2ExceptionTest.java44ƒ…throwJavaJava0try-catch-finallythrowThrowableExceptionƒƒJDKƒException/RuntimeExceptionƒErrorErrorThrowableErrorRuntimeExceptionRuntimeExceptionThrowableException:classMyExceptionextendsException{…}P4777.4InheritTest.java„Java“”(if)try{Javastatement;}catche(ExceptionType1ExceptionObject1){ExceptionObject1handling;}catche(ExceptionType2ExceptionObject2){ExceptionObject2handling;}…finally{finalhandling;//,}ƒJavaƒ„throwsƒ()JavaƒthrownewDefExceptionType()„ThrowableException„finally„:“”„„„„

1 / 25
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功