当前位置:网站首页>第十天 异常机制
第十天 异常机制
2022-04-23 16:02:00 【Students Mr sun】








例子:

--异常捕获级别



throw用在方法中 throwd在方法上抛出异常
package oop.exception;
public class Demo1 {
public static void main(String[] args) {
int a=1;
int b=0;
//ctrl+alt+t 异常快捷键
//捕获异常
try {
System.out.println(a / b);
} catch (Error e) {
System.out.println("Error");
//打印异常 e.printStackTrace();
}
catch (Exception e) {
System.out.println("Exception");
} catch (Throwable e) {
System.out.println("Throwable");
}
finally {
System.out.println("finally");
}
//test方法中的捕获异常
try {
test(1,0);
} catch (ArithmeticException e) {
System.out.println("asdasfasfasfas");
} finally {
System.out.println("finally");
}
}
public static void test(int a,int b) throws ArithmeticException {
if (b==0) {
System.out.println("asd");
throw new ArithmeticException();
}
}
}
自定义异常



版权声明
本文为[Students Mr sun]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_37138380/article/details/120039430
边栏推荐
- Start Oracle service on Linux
- Win11 / 10 home edition disables the edge's private browsing function
- Coalesce and repartition of spark operators
- Es common query, sorting and aggregation statements
- Grbl learning (I)
- [section 5 if and for]
- CVPR 2022 quality paper sharing
- Configuration of multi spanning tree MSTP
- Install redis and deploy redis high availability cluster
- Go language, condition, loop, function
猜你喜欢

GRBL学习(一)

Pgpool II 4.3 Chinese Manual - introductory tutorial

安装Redis并部署Redis高可用集群

Construction of esp32 compilation environment

Filter usage of spark operator

一文读懂串口及各种电平信号含义

R语言中绘制ROC曲线方法二:pROC包

Meaning and usage of volatile

5 minutes, turn your excel into an online database, the magic cube net table Excel database

C language self compiled string processing function - string segmentation, string filling, etc
随机推荐
Ice -- source code analysis
Config组件学习笔记
如何进行应用安全测试(AST)
299. 猜数字游戏
Win11/10家庭版禁用Edge的inprivate浏览功能
The length of the last word of the string
捡起MATLAB的第(9)天
安装Redis并部署Redis高可用集群
C, calculation method and source program of bell number
Spark 算子之partitionBy
Calculate the number of occurrences of a character
Matplotlib tutorial 05 --- operating images
pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)
How can poor areas without networks have money to build networks?
运维流程有多重要,听说一年能省下200万?
volatile的含义以及用法
Leetcode-374 guess the size of the number
面试题 17.10. 主要元素
Day (9) of picking up matlab
Pgpool II 4.3 Chinese Manual - introductory tutorial