当前位置:网站首页>第十天 异常机制
第十天 异常机制
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
边栏推荐
- [key points of final review of modern electronic assembly]
- gps北斗高精度卫星时间同步系统应用案例
- Day (8) of picking up matlab
- Go concurrency and channel
- ES常用查询、排序、聚合语句
- 撿起MATLAB的第(9)天
- Day (4) of picking up matlab
- 安装Redis并部署Redis高可用集群
- Large factory technology implementation | industry solution series tutorials
- Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
猜你喜欢

R语言中实现作图对象排列的函数总结

Cap theorem

Configuration of multi spanning tree MSTP
![[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope](/img/39/4d37c381f16dbe11acc64c92d0a1e5.png)
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope

Day (8) of picking up matlab

Spark 算子之groupBy使用

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

Spark 算子之coalesce与repartition

Best practices of Apache APIs IX high availability configuration center based on tidb

【现代电子装联期末复习要点】
随机推荐
Config组件学习笔记
贫困的无网地区怎么有钱建设网络?
多线程原理和常用方法以及Thread和Runnable的区别
如何进行应用安全测试(AST)
Go concurrency and channel
Merging of Shanzhai version [i]
保姆级Anaconda安装教程
Spark 算子之groupBy使用
Extract non duplicate integers
Jour (9) de ramassage de MATLAB
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Unity shader learning
Day (5) of picking up matlab
Unity Shader学习
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
JS regular determines whether the port path of the domain name or IP is correct
Ice -- source code analysis
dlopen/dlsym/dlclose的简单用法
Treatment of idempotency
One brush 313 sword finger offer 06 Print linked list from end to end (E)