当前位置:网站首页>自定义异常
自定义异常
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;
}
}
测试自定义的异常,如下图:
边栏推荐
- 数据分析常见的英文缩写(一)
- Record an interview
- Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
- Table responsive layout tips
- Base64 coding can be understood this way
- 哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
- 18_ Redis_ Redis master-slave replication & cluster building
- 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
- 21_ Redis_ Analysis of redis cache penetration and avalanche
- Infra11199 database system
猜你喜欢
工程师评测 | RK3568开发板上手测试
02_ Linear table_ Sequence table
. Solution to the problem of Chinese garbled code when net core reads files
TiDB数据迁移工具概览
21_ Redis_ Analysis of redis cache penetration and avalanche
Tidb data migration tool overview
08_ 串
Base64 coding can be understood this way
yolo格式数据集处理(xml转txt)
你不知道的Set集合
随机推荐
Application of CDN in game field
Map introduction
如何对 TiDB 进行 TPC-C 测试
List集合&UML图
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
XML Configuration File
Data analysis thinking analysis methods and business knowledge - business indicators
04_ 栈
LeetCode刷题——验证二叉树的前序序列化#331#Medium
Common English abbreviations for data analysis (I)
08_ 串
Solve the problem of frequent interruption of mobaxterm remote connection
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
07_ Hash
Internet Explorer officially retired
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
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
SQL transaction
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
Case introduction and problem analysis of microservice