当前位置:网站首页>第十天 异常机制
第十天 异常机制
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 rotation function
- Win11/10家庭版禁用Edge的inprivate浏览功能
- CVPR 2022 quality paper sharing
- Named in pytoch_ parameters、named_ children、named_ Modules function
- Pgpool II 4.3 Chinese Manual - introductory tutorial
- MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
- Temporal model: long-term and short-term memory network (LSTM)
- Matplotlib tutorial 05 --- operating images
- How important is the operation and maintenance process? I heard it can save 2 million a year?
- Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
猜你喜欢
随机推荐
C, calculation method and source program of bell number
C language --- string + memory function
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
Unity shader learning
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention
Leetcode-396 rotation function
How important is the operation and maintenance process? I heard it can save 2 million a year?
通过Feign在服务之间传递header请求头信息
Upgrade MySQL 5.1 to 5.610
Day (8) of picking up matlab
Pgpool II 4.3 Chinese Manual - introductory tutorial
【现代电子装联期末复习要点】
OAK-D树莓派点云项目【附详细代码】
下载并安装MongoDB
ESP32_ Arduino
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
Vision of building interstellar computing network
Master vscode remote GDB debugging
The length of the last word of the string
JVM - Chapter 2 - class loader subsystem