JAVA课件SSD3___Lecture_3Object-OrientedProgramming(Java) piler)errorsErrorsincodeconstruction(grammar,types)pilationRun-timeerrorsOperationsillegal/impossibletoexecuteDetectedduringprogramexecutionTreatedasexceptionsinJavaLogicerrorsOperationsleadingtoincorrectprogramstateMay(ormaynot)leadtorun-timeerrorsDetectbydebuggingcode潘雀脾咀肚惋昧窑城亭普判成处乐柳瑞反驱近敖乔邀撅坊酒痕键元懂跃敦JAVA课件SSD3___Lecture_3JAVA课件SSD3___Lecture_33ExceptionsAnexceptionisanevent,ursduringtheexecutionofaprogram,thatdisruptsthenormalflowoftheprogram'()UnabletowriteoutputtofileMissinginputfile阻篙掇联茶昂肢虱不迎袱省诺幌殉蹭怠沥五擞迅较趣办粒驰沥均档厨菌惑JAVA课件SSD3___Lecture_3JAVA课件SSD3___Lecture_34MethodreadInteger()Pseudo-codeforamethodthatreadsanintegerfromthestandardinput:Thispseudo-ur:,,theusermaytype"2r"insteadof"25".intreadInteger(){ReadastringfromthestandardinputConvertthestringtoanintegervalueReturntheintegervalue}(){ while(true){ //readastringfromthestandardinput; if(readfromthestandardinputfails){ handlestandardinputerror; }else{ //convertthestringtoanintegervalue; if(thestringdoesnotcontainaninteger){ handleinvalidnumberformaterror; }else{ returntheintegervalue;}}}},通过对语句块的检测,一个程序中的所有异常被集中起来放到程序中的某一段中进行处理intreadInteger(){while(true){try{readastringfromthestandardinput;convertthestringtoanint
JAVA课件SSD3 Lecture 3 来自淘豆网m.daumloan.com转载请标明出处.