RuntimeException 子类

  • RuntimeException子类
    • ArithmeticException
    • ArrayIndexOutOfBoundsException
    • ArrayStoreException
    • ClassCastException
    • EnumConstantNotPresentException
    • IllegalArgumentException
    • IllegalMonitorStateException
    • IllegalStateException
    • IllegalThreadStateException
    • IndexOutOfBoundsException
    • NegativeArraySizeException
    • NullPointerException
    • NumberFormatException
    • SecurityException
    • StringIndexOutOfBoundsException
    • TypeNotPresentException
    • UnsupportedOperationException
  • 如何通过IDEA查找类及子类源码

RuntimeException子类

有时候总是会区分不清哪些异常类是RuntimeException的子类,这里特意去源码里面找来整理一下,方便后续查阅,由于RuntimeException在java.lang包下,所以这里也只介绍java.lang包下的RuntimeException子类,通常java.lang包下的异常子类也是遇到比较多的

下面逐一介绍每个子类发生的场景

ArithmeticException

当出现异常的运算条件时,抛出此异常。例如,一个整数"除以零"时,抛出此类的一个实例。
Thrown when an exceptional arithmetic condition has occurred. For example, an integer “divide by zero” throws an instance of this class.

ArrayIndexOutOfBoundsException

用非法索引访问数组时抛出的异常。如果索引为负或大于等于数组大小,则该索引为非法索引。
Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.

ArrayStoreException

试图将错误类型的对象存储到一个对象数组时抛出的异常。
Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example, the following code generates an
ArrayStoreException:
Object x[] = new String[3];
x[0] = new Integer(0);

ClassCastException

当试图将对象强制转换为不是实例的子类时,抛出该异常。
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a
ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);

EnumConstantNotPresentException

Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name.
This exception can be thrown by the {@linkplain java.lang.reflect.AnnotatedElement API used to read annotations reflectively}.

IllegalArgumentException

抛出的异常表明向方法传递了一个不合法或不正确的参数。
Thrown to indicate that a method has been passed an illegal or inappropriate argument.

IllegalMonitorStateException

抛出的异常表明某一线程已经试图等待对象的监视器,或者试图通知其他正在等待对象的监视器而本身没有指定监视器的线程。
Thrown to indicate that a thread has attempted to wait on an object’s monitor or to notify other threads waiting on an object’s monitor without owning the specified monitor.

IllegalStateException

在非法或不适当的时间调用方法时产生的信号。换句话说,即 Java 环境或 Java 应用程序没有处于请求操作所要求的适当状态下。
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.

IllegalThreadStateException

线程没有处于请求操作所要求的适当状态时抛出的异常。
Thrown to indicate that a thread is not in an appropriate state for the requested operation. See, for example, the
suspend and resume methods in class Thread.

IndexOutOfBoundsException

指示某排序索引(例如对数组、字符串或向量的排序)超出范围时抛出。
Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out of range.

NegativeArraySizeException

如果应用程序试图创建大小为负的数组,则抛出该异常。
Thrown if an application tries to create an array with negative size.

NullPointerException

当应用程序试图在需要对象的地方使用 null 时,抛出该异常
Thrown when an application attempts to use {@code null} in a case where an object is required. These include:
Calling the instance method of a {@code null} object.
Accessing or modifying the field of a {@code null} object.
Taking the length of {@code null} as if it were an array.
Accessing or modifying the slots of {@code null} as if it
were an array.
Throwing {@code null} as if it were a {@code Throwable}
value.
Applications should throw instances of this class to indicate other illegal uses of the {@code null} object.
{@code NullPointerException} objects may be constructed by the virtual machine as if {@linkplain Throwable#Throwable(String, Throwable, boolean, boolean) suppression were disabled and/or the stack trace was not writable}.

NumberFormatException

当应用程序试图将字符串转换成一种数值类型,但该字符串不能转换为适当格式时,抛出该异常。
Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

SecurityException

由安全管理器抛出的异常,指示存在安全侵犯。
Thrown by the security manager to indicate a security violation.

StringIndexOutOfBoundsException

此异常由 String 方法抛出,指示索引或者为负,或者超出字符串的大小。
Thrown by {@code String} methods to indicate that an index is either negative or greater than the size of the string. For some methods such as the charAt method, this exception also is thrown when the index is equal to the size of the string.

TypeNotPresentException

Thrown when an application tries to access a type using a string representing the type’s name, but no definition for the type with the specified name can be found. This exception differs from {@link ClassNotFoundException} in that ClassNotFoundException is a checked exception, whereas this exception is unchecked.
Note that this exception may be used when undefined type variables are accessed as well as when types (e.g., classes, interfaces or annotation types) are loaded.
In particular, this exception can be thrown by the {@linkplain java.lang.reflect.AnnotatedElement API used to read annotations reflectively}.

UnsupportedOperationException

当不支持请求的操作时,抛出该异常。
Thrown to indicate that the requested operation is not supported.

如何通过IDEA查找类及子类源码

我用的是IDEA 2020版本,首先全局搜索你想要查找的父类,比如 RuntimeException

Ctrl+鼠标左键点击1处的RuntimeException,可以直接RuntimeException类

点击红框可以看到所有继承RuntimeException的子类,包括我们想要看的java.lang包下的子类

这个时候点击1处可以看到,

下滑即可找到我们想要看的java.lang下的RuntimeException的子类,同样的方法也可以去查看Exception的子类,如图

通过阅读源码可以让我们更深入的理解父类子类关系,在工作中多看多用,知识自然就记忆不忘了。
参考文章:https://developer.aliyun.com/article/981052

RuntimeException 子类相关推荐

  1. Java基础-异常(Exception)处理

    Java基础-异常(Exception)处理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.异常的概述 什么是异常?Java代码在运行时期发生的问题就是异常.在Java中,把异 ...

  2. java抛出数组格式异常,Java中异常

    一.异常的概述 在Java中,把异常信息封装成了一个类.当出现了问题时,就会创建异常类对象并抛出异常相关的信息(如异常出现的位置.原因等). 二.异常的继承体系和错误的区别 1.异常的继承体系 Thr ...

  3. Spring事务传播性与隔离级别

    为什么80%的码农都做不了架构师?>>>    事务是逻辑处理原子性的保证手段,通过使用事务控制,可以极大的避免出现逻辑处理失败导致的脏数据等问题. 事务最重要的两个特性,是事务的传 ...

  4. 了解Java中的检查与未检查异常

    约书亚·布洛赫(Joshua Bloch)在< 有效的Java >中说 将检查的异常用于可恢复的条件,将运行时异常用于编程错误(第二版中的项目58) 让我们看看我是否正确理解了这一点. 这 ...

  5. 简述java异常处理机制

    引言: Hello,我的好朋友们,又到我们相聚的时间了,今天我要和大家分享一些有关java异常处理的相关 知识,也是通过老师的讲解和相关材料的借鉴之后的一个比较系统的总结,真心希望写完这篇文章的我和看 ...

  6. 11.2运行异常和编译异常

    异常体系 ------------|Throwable(super类) ----------------|Error(错误) ----------------|Exception(异常) ------ ...

  7. Java入门学习笔记[狂神说Java]

    写在前面: 本文根据B站狂神说Java 与菜鸟教程 整理而来,仅供个人学习使用,如有侵权,请联系删除. 文章目录 IDEA使用 Java基础01:注释 Java基础02:数据类型 Java基础03:类 ...

  8. 深入理解java异常处理机制

    1. 引子 try-catch-finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解.不过,我亲自体验的"教训"告诉我,这个东西可不是想象 ...

  9. 21_异常_第21天(异常、企业面试题,思维导图下载)

    今日内容介绍 1.异常概述和继承体系 2.异常原因以及处理方式 3.运行时期异常 4.方法重写的异常处理 5.Throwable类常见方法 6.自定义异常 xmind:下载地址 链接:https:// ...

最新文章

  1. iOS开源JSON解析库MJExtension
  2. python插入排序演示源码
  3. 统计学习导论 Chapter4--Classification
  4. Linux脚本获取日期,Shell脚本获取格式化日期与时间
  5. linux集群流程运行,linux 怎么配置集群
  6. Linux查看网卡UUID另一方法
  7. java多线程之Semaphore信号量详解
  8. python函数代码,这个python函数代码如何工作?
  9. python大文件去重_python3 大文件去重
  10. 世界上最好的惯性动作捕捉设备Xsens,你不应该错过的Xsens MVN Animate Pro
  11. 【环境配置】Ubuntu18.04配置高通骁龙神经处理引擎(SNPE)
  12. java+es+nested_Elasticsearch中的关联查询。Nested类型介绍及查询原理。。
  13. python3强智教务系统个人课表爬虫
  14. 超出预算,他的处理的方式对吗? | 每天成就更大成功
  15. 如何把很多照片拼成一张照片_怎样用手机将多张照片拼成一张组合图?
  16. 评价指标(metrics)
  17. 你知道什么是 a站、b站、c站、d站、e站、f站、g站、h站、i站、j站、k站、l站、m站、n站…z 站吗 ?...
  18. php地铁,php 抓取自如友家首页的区域和地铁数据
  19. 许多博士生的一个通病:对导师过度依赖!
  20. AdGuard家长控制模式的运用

热门文章

  1. linux中fdisk管理分区
  2. 获取TTF里面的字体名称
  3. ImageView和Glide的ScaleType
  4. 【EI检索-SPIE出版】第四届计算机科学与通信技术国际学术会议
  5. Connected Components
  6. 心中无敌,天下无敌——转“赢在中国”主持人王利芬的博客片断
  7. 梅艳芳吴君如为争华仔反目 朱丽倩渔翁得利
  8. python秒表_使用Python创建秒表
  9. 第五章:尺寸处理(1)
  10. 【D3.js实战】 品牌排名动态可视化