当前位置:网站首页>第十天 异常机制
第十天 异常机制
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
边栏推荐
- 捡起MATLAB的第(3)天
- Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
- Load Balancer
- Extract non duplicate integers
- PS add texture to picture
- 糖尿病眼底病变综述概要记录
- C语言自编字符串处理函数——字符串分割、字符串填充等
- C language self compiled string processing function - string segmentation, string filling, etc
- Fastjon2他来了,性能显著提升,还能再战十年
- OAK-D树莓派点云项目【附详细代码】
猜你喜欢
随机推荐
R语言中绘制ROC曲线方法二:pROC包
GRBL学习(一)
Treatment of idempotency
实现缺省页面
shell_2
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
Matplotlib tutorial 05 --- operating images
R语言中实现作图对象排列的函数总结
糖尿病眼底病变综述概要记录
Function summary of drawing object arrangement in R language
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
Load Balancer
【第5节 if和for】
JVM - Chapter 2 - class loader subsystem
Go language slice, range, set
Spark 算子之filter使用
Spark 算子之sortBy使用
Sortby use of spark operator
linux上启动oracle服务
5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库








