码迷,mamicode.com
首页 > 其他好文 > 详细

自定义异常时如何定义checked异常和unchecked异常

时间:2015-08-16 00:32:21      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

When defining your own exception type, study the existing exception classes in the Java API and try to extend a related exception class. For example, if you’re creating a new class to represent when a method attempts a division by zero, you might extend classArithmeticException because division by zero occurs during arithmetic. If the existing classes are not appropriate superclasses for your new exception class, decide whether your new class should be a checked or an unchecked exception class. If clients should berequired to handle the exception, the new exception class should be a checked exception (i.e., extend Exception but notRuntimeException). The client application should be able to reasonably recover from such an exception. If the client code should be able to ignore the exception (i.e., the exception is an unchecked one), the new exception class should extend RuntimeException.

 

自定义异常时如何定义checked异常和unchecked异常

标签:

原文地址:http://www.cnblogs.com/IcanFixIt/p/4733324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!