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异常的更多相关文章

  1. java中checked异常和unchecked异常区别?

    马克-to-win:checked和unchecked异常区别:结论就是:1)RuntimeException和他的子类都是unchecked异 常.其他的都是checked异常.马克-to-win: ...

  2. Java异常:选择Checked Exception还是Unchecked Exception?

    http://blog.csdn.net/kingzone_2008/article/details/8535287 Java包含两种异常:checked异常和unchecked异常.C#只有unch ...

  3. Java的checked exception与unchecked exception

    在Java中exception分为checked exception和unchecked异常,两者有什么区别呢? 从表象来看, checked异常就是需要在代码中try ... catch ...的异 ...

  4. Checked 和 UnChecked 异常 的使用场合

    异常的概念  任何的异常都是Throwable类(为何不是接口??),并且在它之下包含两个子类Error / Exception,而Error仅在当在Java虚拟机中发生动态连接失败或其它的定位失败的 ...

  5. 基础知识《十》unchecked异常和checked异常

    运行时异常在运行期间才能被检查出来,一般运行期异常不需要处理.也称为unchecked异常.Checked异常在编译时就能确定,Checked异常需要自己处理. checked 异常也就是我们经常遇到 ...

  6. java异常—检查异常(checked exception)和未检查异常(unchecked exception)

    网易面试要我画异常的结构图,什么是检查异常,什么是非检查异常,我当时的表情是这样的,.我看过,忘了.没办法,继续看,写博客掌握. 先来看看异常的结构图,建议你结合JDK一起看. 可以看出异常的家族势力 ...

  7. 检查型异常(Checked Exception)与非检查型异常(Unchecked Exception)

    这两个概念看了忘,碰着了又看,老是傻傻的分不清楚,今天把心得结合从网上搜的资料简单整理一下,希望帮自己明确区分开这两个概念,并牢牢的记住 1.检查型异常(Checked Exception) 个人理解 ...

  8. 牛客网Java刷题知识点之什么是异常、异常处理的原理是什么、为什么要使用异常、异常体系、运行时异常、普通异常、自定义异常、异常链

    不多说,直接上干货! 在这个世界不可能存在完美的东西,不管完美的思维有多么缜密,细心,我们都不可能考虑所有的因素,这就是所谓的智者千虑必有一失.同样的道理,计算机的世界也是不完美的,异常情况随时都会发 ...

  9. Java 检查异常(checked exception)和未检查异常(unchecked exception)区别理解

    所有异常类型都是 Throwable 类的子类,它包含Exception类和Error类,Exception又包括checked exception和unchecked exception. unch ...

随机推荐

  1. 如何循序渐进地学习Javascript

    javascript入门太容易了,导致几乎人人随便看看就能上手,零基础的人学个三五天都能对外宣称自己掌握了js.可是真正掌握js是一件很难的事情.如果在初学一门语言的时候第一想到的是问别人,是很难取得 ...

  2. jquery.form.js实现将form提交转为ajax方式提交的使用方法

    本文实例讲述了jquery.form.js实现将form提交转为ajax方式提交的方法.分享给大家供大家参考.具体分析如下: 这个框架集合form提交.验证.上传的功能. 这个框架必须和jquery完 ...

  3. php小算法总结一(数组重排,进制转换)

    1.两个有序数组组合成一个新的有序数组 <?php $arr1=array(2,5,7,9,12); $arr2=array(3,4,6,8,10,11); function merge_sor ...

  4. php 安装pdo_mysql 扩展

    如果pdo在linux下出现exception 'PDOException' with message 'could not find driver'则问题是php编译时少加--with-pdo-my ...

  5. a标签至于flash之上的时候,IE浏览器无法点击连接的问题

    <a style="display: block;height: 131px;position: absolute;z-index: 999;width: 222px;backgrou ...

  6. vc++ 内存连续读写操作

    //初始化内存 int *data=(int*)malloc(sizeof(int)*4); ZeroMemory(data, sizeof(int)*4); int *m=(int*)malloc( ...

  7. 删:Centos 7安装Nginx 1.8

    [CentOS 7] 安装nginx! 首先进行 nginx yum Nginx安装记录 注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要 ...

  8. 18)Java八股文名词

      >VO:   value-object >DTO: Data Transform Object >DTD: Document Type Definition      文档类型定 ...

  9. 12)Java Constructor

    Constructor        构造器Constructor不能被继承,因此不能重写Overriding,但可以被重载Overloading.     构造器用来确保每个对象都会得到初始化.当对 ...

  10. c#写入Mysql中文显示乱码 解决方法

    如题,mysql字符集utf8,c#写入中文后,全部显示成?,一个汉字对应一个?解决方法:在数据库连接字符串中增加字符集的说明,Charset=utf8,如 MySQLConnection con = ...