自定义异常时如何定义checked异常和unchecked异常
2015-08-15 23:08
246 查看
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.
相关文章推荐
- HDU 5391 Zball in Tina Town(数论——威尔逊定理)——BestCoder Round #51(div.2)
- ZOJ - 3469 Food Delivery(区间DP)
- 安装 GitHub desktop for windows 失败
- handle()
- Android开发PopupWindow showAtLocation用法
- String和StringBuffer的equals方法比较
- 笨笨熊搬家——交通(java)
- c++ public, protected, private成员变量,成员函数继承和访问规则实例代码
- Gym - 100203H Highways 最小生成树
- Nginx 引入线程池,提升 9 倍性能
- 自然数和分解
- 多线程基本概论multithread
- 庖丁解羊----划分
- 正宗冒泡法-java语言实现
- 求一个数阶乘的位数
- 12c PDB备份与恢复初体验
- PAT 1082. Read Number in Chinese (25)
- 黑马程序员------OC中计算NSString 字符串的长度
- 系统函数C字符串的实现(7):wcsrev
- java类集框架图(google找的,备个份)