当前位置:网站首页>自定义异常
自定义异常
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;
}
}

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

边栏推荐
- Summary of the first three passes of sqli Labs
- TiDB数据迁移场景综述
- Yolov5 code reproduction and server operation
- 05_队列
- The past and present lives of visual page building tools
- 08_ 串
- Recommended configuration of tidb software and hardware environment
- Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
- 16_ Redis_ Redis persistence
- TiDB数据迁移工具概览
猜你喜欢

How to avoid 7 common problems in mobile and network availability testing

Table responsive layout tips

Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?

08_ 串

Data analysis thinking analysis methods and business knowledge - business indicators

18_Redis_Redis主从复制&&集群搭建

Leetcode question brushing - parity linked list 328 medium

Practical debugging skills

Bing.com網站

Bing. Com website
随机推荐
数据分析常见的英文缩写(一)
03_線性錶_鏈錶
Learn the method code example of converting timestamp to uppercase date using PHP
Semantic segmentation learning notes (1)
TiDB 集群最小部署的拓扑架构
【网络安全】网络资产收集
How to test tidb with sysbench
Tidb data migration tool overview
04_ Stack
16_Redis_Redis持久化
The traversal methods of binary tree mainly include: first order traversal, middle order traversal, second order traversal, and hierarchical traversal. First order, middle order, and second order actu
XML配置文件
Solution of Queen n problem
Oracle primary key auto increment
04_ 栈
08_ 串
Leetcode skimming -- incremental ternary subsequence 334 medium
XML Configuration File
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
19_Redis_宕机后手动配置主机