当前位置:网站首页>第十天 异常机制
第十天 异常机制
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
边栏推荐
猜你喜欢

How can poor areas without networks have money to build networks?

Construction of esp32 compilation environment

运维流程有多重要,听说一年能省下200万?

糖尿病眼底病变综述概要记录

Spark 算子之sortBy使用

CVPR 2022 quality paper sharing
![[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention](/img/bf/2b4914276ec1083df697383fec8f22.png)
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention

Function summary of drawing object arrangement in R language

C#,贝尔数(Bell Number)的计算方法与源程序

安装Redis并部署Redis高可用集群
随机推荐
捡起MATLAB的第(7)天
Implement default page
Config组件学习笔记
贫困的无网地区怎么有钱建设网络?
Compile, connect -- Notes
Algorithem_ ReverseLinkedList
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
linux上启动oracle服务
通过Feign在服务之间传递header请求头信息
捡起MATLAB的第(10)天
Configuration of multi spanning tree MSTP
Start Oracle service on Linux
安装Redis并部署Redis高可用集群
C language --- advanced pointer
C#,贝尔数(Bell Number)的计算方法与源程序
Day (9) of picking up matlab
Upgrade MySQL 5.1 to 5.610
面试题 17.10. 主要元素
Distinct use of spark operator
Named in pytoch_ parameters、named_ children、named_ Modules function