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

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

边栏推荐
- Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
- Steps for Navicat to create a new database
- Build your own semantic segmentation platform deeplabv3+
- Engineer evaluation | rk3568 development board hands-on test
- Markdown tutorial
- 04_ 栈
- TiDB 集群最小部署的拓扑架构
- TiDB 环境与系统配置检查
- Application and practice of Jenkins pipeline
- 13_Redis_事务
猜你喜欢

Let your HMI have more advantages. Fet-g2ld-c core board is a good choice

Kibana basic operation

党史纪实主题公益数字文创产品正式上线

Case introduction and problem analysis of microservice

微信支付宝账户体系和支付接口业务流程

LeetCode刷题——两整数之和#371#Medium

Storage read-write speed and network measurement based on rz/g2l | ok-g2ld-c development board

04_ 栈

03_ Linear table_ Linked list

4. Jctree related knowledge learning
随机推荐
TiDB混合部署拓扑
21_ Redis_ Analysis of redis cache penetration and avalanche
How does the computer set up speakers to play microphone sound
Kibana basic operation
Tidb cross data center deployment topology
06_栈和队列转换
PHP method to get the index value of the array item with the largest key value in the array
数据分析常见的英文缩写(一)
Record an interview
Internet Explorer officially retired
TiDB 环境与系统配置检查
Application of CDN in game field
4. Jctree related knowledge learning
TiDB 软件和硬件环境建议配置
TiDB 集群最小部署的拓扑架构
JVM architecture, classloader, parental delegation mechanism
做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统
4. Data splitting of Flink real-time project
02_ Linear table_ Sequence table
Mavn builds nexus private server