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.
相关文章
- C#不用union,而是有更好的方式实现 .net自定义错误页面实现 .net自定义错误页面实现升级篇 .net捕捉全局未处理异常的3种方式 一款很不错的FLASH时种插件 关于c#中委托使用小结 WEB网站常见受攻击方式及解决办法 判断URL是否存在 提升高并发量服务器性能解决思路
- Java斗地主案例、异常和自定义异常整理
- java异常,异常处理,异常类 关键字:throws 和 throw 自定义的异常类
- 关于thinkphp5手动抛出Http异常时自定义404页面报错的问题
- java基础之自定义异常类及throw和throws的区别
- JAVA之旅(十)——异常的概述,Try-Catch,异常声明Throws,多异常处理,自定义异常,Throw和Throws的区别
- Java 面向对象 异常处理:RunTimeexception,try-catch,异常声明throws,自定义异常,throw和throws的区别,多异常处理(9)
- EF 自定义校验设置和捕获异常
- 如何自定义异常?
- java异常—检查异常(checked exception)和未检查异常(unchecked exception)