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

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

边栏推荐
- MD5加密
- List集合&UML图
- How to write sensor data into computer database
- 搭建自己的语义分割平台deeplabV3+
- How does the computer set up speakers to play microphone sound
- 08_ strand
- 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
- 19_Redis_宕机后手动配置主机
- How to choose a third-party software testing organization for automated acceptance testing of mobile applications
- 21_ Redis_ Analysis of redis cache penetration and avalanche
猜你喜欢
随机推荐
数据分析思维分析方法和业务知识——业务指标
LeetCode刷题——验证二叉树的前序序列化#331#Medium
LeetCode刷题——去除重复字母#316#Medium
17_Redis_Redis发布订阅
02.面向容器化后,必须面对golang
Principles, language, compilation, interpretation
Solution of Queen n problem
13_Redis_事务
Tidb data migration scenario overview
Engineer evaluation | rk3568 development board hands-on test
4. Data splitting of Flink real-time project
Record an interview
面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
Yolov5 code reproduction and server operation
15_Redis_Redis.conf详解
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
How to avoid 7 common problems in mobile and network availability testing
如何用 Sysbench 测试 TiDB
Real estate market trend outlook in 2022
LeetCode刷题——奇偶链表#328#Medium








