Chinaunix首页 | 论坛 | 博客
  • 博客访问: 237001
  • 博文数量: 108
  • 博客积分: 3092
  • 博客等级: 中校
  • 技术积分: 1172
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-25 16:35
文章分类

全部博文(108)

文章存档

2011年(3)

2010年(43)

2009年(19)

2008年(43)

我的朋友

分类: Java

2010-05-23 12:09:33

 
1. some definations

When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.
2. Exception handle, call stack

When an Exception occurred, the code will search though the call stack in a reverse order to match the handler.
 
3.Three kinds of Exceptios
1)checked Exceptions:a client can reasonably be expected to recover from the exception.
eg:sometimes the user supplies the name of a nonexistent file, and the constructor throws java.io.FileNotFoundException. A well-written program will catch this exception and notify the user of the mistake, possibly prompting for a corrected file name.
2)unchecked Exceptions:a client cann't recover
   error:not subject to the Catch or Specify Requirement
   runTime Exceptions:These usually indicate programming bugs, such as logic errors or improper use of an API.
eg:NullPointerException, IndexOutofrangeException
 
4.Advantages
1)separate error-handling code from "regular" code
  It makes the logical structure of the codes more clearly and easier to read.
2)propagating errors up the call back
  In traditional way, you need to pass the error code by parameters.
3)grouping and differentiating error types.
  Objects are natually have this character.
 
 

 
阅读(474) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~