当前位置:网站首页>第十天 异常机制
第十天 异常机制
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
边栏推荐
- leetcode-396 旋转函数
- [AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention
- Why disable foreign key constraints
- s16. One click installation of containerd script based on image warehouse
- Day (6) of picking up matlab
- Meaning and usage of volatile
- Day (5) of picking up matlab
- volatile的含义以及用法
- Config组件学习笔记
- WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
猜你喜欢
MySQL optimistic lock to solve concurrency conflict
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
Why disable foreign key constraints
How important is the operation and maintenance process? I heard it can save 2 million a year?
Ice -- source code analysis
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
Day (6) of picking up matlab
Partitionby of spark operator
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库
随机推荐
Day (8) of picking up matlab
VIM specifies the line comment and reconciliation comment
Date date calculation in shell script
王启亨谈Web3.0与价值互联网“通证交换”
Grbl learning (I)
Intersection, union and difference sets of spark operators
Do we media make money now? After reading this article, you will understand
运维流程有多重要,听说一年能省下200万?
撿起MATLAB的第(9)天
捡起MATLAB的第(6)天
Load Balancer
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
Meaning and usage of volatile
C language self compiled string processing function - string segmentation, string filling, etc
Spark 算子之sortBy使用
Algorithem_ ReverseLinkedList
Fastjon2他来了,性能显著提升,还能再战十年
leetcode-374 猜数字大小
String sorting
Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)