当前位置:网站首页>认识异常 (看完这篇你就懂了)
认识异常 (看完这篇你就懂了)
2022-07-31 16:34:00 【不会写代码_】
系列文章目录
文章目录
一、概念

二、基本用法
2.1基本语法

2.2程序中不处理异常

2.3try…catch处理异常
一旦 try 中出现异常, 那么 try 代码块中的程序就不会继续执行, 而是交给 catch 中的代码来执行. catch 执行完毕会继续往下执行

2.4异常也是类

catch可以接收多种异常类型

Excpetion类(不推荐)


2.5错误堆栈信息
打印异常出现的位置及原因
2.6finally代码块

eg:如果关闭资源的代码块在try代码块中,产生异常就无法执行。如果放在catch代码块中,代码不产生异常也无法关闭资源代码块。
不要在finally代码块写返回值

2.7异常处理流程


2.8 throws和throw关键字



三、异常体系
3.1 JDK异常继承体系


3.2非受查异常
常见的非受查异常:空指针异常,数组越界异常,类型转换异常

3.3受查异常

显示处理

四、自定义异常
自定义异常:
JDK内部已经帮我们提前定义好了很多的异常类,但是在某些业务场景下,出现的错误需要我们自定义异常类(佣户登录的时候,用户名不对,密码不对,这种错误就需要我们来自定义异常类)
边栏推荐
- How to switch remote server in gerrit
- Character pointer assignment [easy to understand]
- 多主复制下处理写冲突(3)-收敛至一致的状态及自定义冲突解决逻辑
- Summary of the implementation method of string inversion "recommended collection"
- Dialogue with Zhuang Biaowei: The first lesson of open source
- 【网络通信三】研华网关Modbus服务设置
- Premiere Pro 2022 for (pr 2022)v22.5.0
- 最新神作!阿里巴巴刚出炉的面试参考指南(泰山版),我直接狂刷29天
- 【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发
- C语言-函数
猜你喜欢

Three aspects of Ali: How to solve the problem of MQ message loss, duplication and backlog?

gerrit中如何切换远程服务器

上传图片-微信小程序(那些年的坑记录2022.4)
![[pytorch] 1.7 pytorch and numpy, tensor and array conversion](/img/ca/b943ff8f59f08e9e23b1ba416c79a0.png)
[pytorch] 1.7 pytorch and numpy, tensor and array conversion

T - sne + data visualization parts of the network parameters

动态规划(一)

Smart Trash Can (8) - Infrared Tube Sensor (Raspberry Pi pico)
![[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development](/img/f6/311d5a4c70993df6291250d2025d3f.jpg)
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development

.NET 20th Anniversary Interview - Zhang Shanyou: How .NET technology empowers and changes the world

动态规划之线性dp(上)
随机推荐
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
华为顶级工程师历时9年总结的“趣谈网络协议”PDF文档,太强了
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
Qt practical cases (54) - using transparency QPixmap design pictures
最后写入胜利(丢弃并发写入)
arm按键控制led灯闪烁(嵌入式按键实验报告)
牛客 HJ18 识别有效的IP地址和掩码并进行分类统计
Replication Latency Case (3) - Monotonic Read
软件实现AT命令操作过程
外媒所言非虚,苹果降价或许是真的在清库存
【TypeScript】深入学习TypeScript类型操作
[pytorch] 1.7 pytorch and numpy, tensor and array conversion
ansible study notes 02
What is the difference between BI software in the domestic market?
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none 失败
"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)
Smart Trash Can (8) - Infrared Tube Sensor (Raspberry Pi pico)
深度学习机器学习理论及应用实战-必备知识点整理分享
js的toString方法
How to install CV2 smoothly in Anaconda