当前位置:网站首页>受检异常和非受检异常的区别和理解
受检异常和非受检异常的区别和理解
2022-07-06 09:20:00 【快醒醒鸭今天你编程了吗?】
1、受检异常
所谓的受检异常其实表示的是在编译的时候,要强制检查的异常,这种异常需要去显示的通过try/catch来进行捕获或者通过throws去抛出去否则程序无法通过编译的。
2、非受检异常
所谓的非受检异常表示编译器可以不需要去强制去检查异常,这种异常不需要去显示去捕获或者抛出。
在java里面所有的异常都需要继承java.lang.Throwable这个类如下图:

Throwable有两个直接的子类:
- Error:表示的是程序底层或者硬件层面的错误,比如像常见的OOM异常(内存溢出异常)那么这种异常和程序本身没有什么关系所以它不需要去检查属于非受检异常。
- Exception:表示的是程序里面的一些异常,可能是由于程序不严谨导致的比如像NullPointerException(空指针异常)等,Exception派生出两种异常类型
- RuntimeException:运行时异常属于非受检异常
- 其他Exception
小结:
所以除了Error和RuntimeException以及RuntimeException的派生类以外,其他的异常都是属于受检异常比如:IOException和SQLException,其实之所以在Java里面去设计一些强制检查的异常我认为主要的原因是:
考虑程序的正确性、稳定性、可靠性,如上述说的数据库异常是程序无法提前预料的异常但是一旦出现问题就会造成资源上的一个占用导致程序出现一些问题,所以这些问题我们要去捕获一旦出现问题可以及时做出相应的处理,如我们进行数据库操作try/catch之后会finally关闭xxx.close关闭连接,所以总的来说受检异常是程序中无法去判断的异常我们去用try/catch进行捕获。
边栏推荐
- First acquaintance with C language (Part 1)
- 2. Preliminary exercises of C language (2)
- MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
- Rich Shenzhen people and renting Shenzhen people
- C语言入门指南
- View UI plus released version 1.3.0, adding space and $imagepreview components
- TYUT太原理工大学2022数据库大题之概念模型设计
- Set container
- 【九阳神功】2017复旦大学应用统计真题+解析
- 5.函数递归练习
猜你喜欢

7. Relationship between array, pointer and array

Pit avoidance Guide: Thirteen characteristics of garbage NFT project

C语言入门指南

Change vs theme and set background picture

System design learning (I) design pastebin com (or Bit.ly)

Rich Shenzhen people and renting Shenzhen people

MPLS experiment

Design a key value cache to save the results of the most recent Web server queries

TYUT太原理工大学2022“mao gai”必背

3. C language uses algebraic cofactor to calculate determinant
随机推荐
5. Function recursion exercise
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
分支语句和循环语句
The overseas sales of Xiaomi mobile phones are nearly 140million, which may explain why Xiaomi ov doesn't need Hongmeng
CorelDRAW plug-in -- GMS plug-in development -- Introduction to VBA -- GMS plug-in installation -- Security -- macro Manager -- CDR plug-in (I)
Relational algebra of tyut Taiyuan University of technology 2022 database
View UI plus released version 1.3.1 to enhance the experience of typescript
Change vs theme and set background picture
TYUT太原理工大学往年数据库简述题
Introduction and use of redis
Smart classroom solution and mobile teaching concept description
西安电子科技大学22学年上学期《信号与系统》试题及答案
The latest tank battle 2022 - Notes on the whole development -2
E-R graph to relational model of the 2022 database of tyut Taiyuan University of Technology
Aurora system model of learning database
(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
String类
System design learning (III) design Amazon's sales rank by category feature