RuntimeException 子类

RuntimeException 子类本文简要介绍RuntimeException及其子类

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

RuntimeException子类

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

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
RuntimeException 子类
Ctrl+鼠标左键点击1处的RuntimeException,可以直接RuntimeException类
RuntimeException 子类
点击红框可以看到所有继承RuntimeException的子类,包括我们想要看的java.lang包下的子类
RuntimeException 子类
这个时候点击1处可以看到,
RuntimeException 子类
下滑即可找到我们想要看的java.lang下的RuntimeException的子类,同样的方法也可以去查看Exception的子类,如图
RuntimeException 子类
通过阅读源码可以让我们更深入的理解父类子类关系,在工作中多看多用,知识自然就记忆不忘了。
参考文章:https://developer.aliyun.com/article/981052

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/213534.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • Kafka连接服务器出现:Connection to node 1 (localhost/127.0.0.1:9092) could not be established.「建议收藏」

    文章目录1.安全组是否开放&防火墙是否拦截请求2.登陆服务器查看Kafkabroker是否可用3.查看Kafka运行日志4.在网上找资料5.解决问题今天遇到个很奇怪的问题,是关于外网连接Kafka的。在服务器本地可以使用命令行参数连接并且进行发布订阅操作,但是在外网环境就不可以了,SpringBoot连接报错:Connectiontonode1(localhost/127….

  • P1983 [NOIP2013] 车站分级(拓扑排序)[通俗易懂]

    P1983 [NOIP2013] 车站分级(拓扑排序)[通俗易懂]原题链接题目描述一条单向的铁路线上,依次有编号为 1, 2, …, n1,2,…,n的 nn个火车站。每个火车站都有一个级别,最低为 11 级。现有若干趟车次在这条线路上行驶,每一趟都满足如下要求:如果这趟车次停靠了火车站 xx,则始发站、终点站之间所有级别大于等于火车站xx 的都必须停靠。(注意:起始站和终点站自然也算作事先已知需要停靠的站点)例如,下表是55趟车次的运行情况。其中,前44 趟车次均满足要求,而第 55 趟车次由于停靠了 33 号火车站(22 级)却未停靠途经的 66 号火车站(亦为

  • ntp时间同步协议_ntp服务器搭建

    ntp时间同步协议_ntp服务器搭建一、简介1.作用NTP是从时间协议(TimeProtocol)和ICMP时间戳报文(ICMPTimeStampMessage)演变而来,在准确性和健壮性方面进行了特殊的设计,理论上精度可达十亿分之一秒。NTP协议应用于分布式时间服务器和客户端之间,实现客户端和服务器的时间同步,从而使网络内所有设备的时钟基本保持一致。NTP协议是基于UDP进行传输的,使用端口号为123。2.特征NTP提供了准…

    2022年10月11日
  • 谷歌清楚缓存快捷键_清除浏览器缓存的快捷键是什么

    谷歌清楚缓存快捷键_清除浏览器缓存的快捷键是什么我们经常会遇到这些情况,浏览器打开网页打不开,打开网页老是在加载。尤其是在我们在做网页设计的时候,经常预览结果往往没有出现我们想要的结果,很大可能性就是浏览器的缓存没有清除引起的。那么清除浏览器缓存的快捷键是什么呢?佰佰安全网就带大家来了解一下这些打开浏览器,按Ctrl+Shift+Delete,就会出现清除浏览器缓存的框,你可以选择你要清理的东西,点击ok,一切搞定。各种浏览器清除缓存数据的方法…

  • pycharm2021激活码10月_在线激活[通俗易懂]

    (pycharm2021激活码10月)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.cn/100143.html…

  • Spring核心——Bean的定义与控制

    Spring核心——Bean的定义与控制

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号