当前位置:网站首页>自定义异常
自定义异常
2022-07-02 12:05:00 【杀手不太冷!】
自定义异常
在程序运行的时候,有的时候执行完一段代码的时候你发现程序代码不符合逻辑,所以我们想要return结束这段代码,但是这段代码所在的方法的返回值类型又是void,因此我们没办法return,所以这个时候要怎么办呢?这个时候我们可以自定义一个异常,然后在方法里面主动抛出去一个异常。
自定义异常代码如下:
/** * @Author zy.xuan * @Date 2022/6/21 14:13 */
public class ComplaintExeception extends RuntimeException {
private String message;
public ComplaintExeception(String message){
this.message = message;
}
@Override
public String toString() {
return message;
}
}

测试自定义的异常,如下图:

边栏推荐
- 04.进入云原生后的企业级应用构建的一些思考
- 學習使用php實現公曆農曆轉換的方法代碼
- The past and present lives of visual page building tools
- 03_线性表_链表
- Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
- Bing. Site Internet
- 19_Redis_宕机后手动配置主机
- Learn the method code example of converting timestamp to uppercase date using PHP
- 语义分割学习笔记(一)
- 5. Practice: jctree implements the annotation processor at compile time
猜你喜欢

Mavn builds nexus private server

语义分割学习笔记(一)

Solve the problem of frequent interruption of mobaxterm remote connection

LeetCode刷题——递增的三元子序列#334#Medium

Engineer evaluation | rk3568 development board hands-on test
![[C language] explain the initial and advanced levels of the pointer and points for attention (1)](/img/61/1619bd2e959bae1b769963f66bab4e.png)
[C language] explain the initial and advanced levels of the pointer and points for attention (1)

How does the computer set up speakers to play microphone sound

. Net again! Happy 20th birthday

Internet Explorer officially retired

XML Configuration File
随机推荐
MySQL -- Index Optimization -- order by
Deploy tidb cluster with tiup
Yolo format data set processing (XML to txt)
14_Redis_乐观锁
Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
15_Redis_Redis.conf详解
04_ 栈
Practical debugging skills
Oracle primary key auto increment
Build your own semantic segmentation platform deeplabv3+
21_ Redis_ Analysis of redis cache penetration and avalanche
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
18_ Redis_ Redis master-slave replication & cluster building
Beijing rental data analysis
Storage read-write speed and network measurement based on rz/g2l | ok-g2ld-c development board
Tidb data migration scenario overview
. Net again! Happy 20th birthday
13_Redis_事务