- 1、本文档共19页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park Java Review Topics Errors Exceptions Debugging Program Errors Types of errors Compile-time (syntax) errors Run-time errors Logic errors Program Errors – Compile Time Compile-time (syntax) errors Errors in code construction Lexical (typographical), grammatical, types Detected during compilation Usually easy to correct quickly Examples Misspelled keyword Missing or misplaced symbol Incorrect operator for variable type Program Errors – Run Time Run-time errors Operations illegal / impossible to execute Detected during program execution But not detectable at compile time Treated as exceptions in Java Example Division by zero Array index out of bounds Using null pointer Illegal format conversion Program Errors – Logic Logic errors Operations leading to incorrect program state May (or may not) lead to run-time errors Problem in design or implementation of algorithm Examples Computing incorrect arithmetic value Ignoring illegal input Hardest error to handle Detect by testing, debugging Java Review Topics Errors Exceptions Debugging Exceptions Rare event outside normal behavior of code Examples Division by zero Access past end of array Out of memory Number input in wrong format (float vs. integer) Unable to write output to file Missing input file Exception Handling – Throw Exception Approach Throw exception Example A( ) { if (error) throw new ExceptionType(); } B( ) { try { A( ); } catch (ExceptionType e) { ...action... } } Representing Exceptions in Java Exceptions represented as Objects derived from class Throwable Code public class Throwable( ) extends Object { Throwable( ) // No error message Throwable( String mesg ) // Error message String getMessage() // Return error mesg void printStackTrace( ) { … } // Record methods … // called location } Generating Handlin
您可能关注的文档
- Civilizations as dynamic networks Eclectic Anthropology作为动态网络的文明折衷的人类学.ppt
- CIVILIZATIONS IN CRISIS, CONFLICT AND CHANGE文明在危机冲突和变化.ppt
- Clasificacin de las discapacidades243 clasificaci与残疾.ppt
- CIWMB Presentation CalRecycle加拿大统一废品管理理事会表示calrecycle.ppt
- Class 1 Northwestern University1级西北大学.ppt
- Class 2 Tues2类课程., Sept. 16th University of Pennsylvania.ppt
- Class 321 Explores Peaceful Solutions Columbia 321级探索和平解决方案哥伦比亚大学.ppt
- Class Exercise Gadjah Mada University课堂练习玛达大学.ppt
- Class Exercises Columbia University课堂练习哥伦比亚大学.ppt
- CLASS OF 2011 COMMENCEMENT ASSEMBLY2011届毕业典礼.ppt
文档评论(0)