当前位置:网站首页>自定义RunTimeException工具类
自定义RunTimeException工具类
2022-08-03 00:56:00 【指导毕业设计Monkey】
自定义异常MyInfoException,将异常提示传递给前端
1. 定义一个异常的工具类extends RuntimeException
package com.monkey;
public class MyRuntimeException extends RuntimeException{
private int code;
MyRuntimeException(int code,String msg){
super(msg);
this.code = code;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public BasicResponse test(){
BasicResponse<Object> objectBasicResponse = new BasicResponse<>();
try {
int i = 6 / 0;
}catch (Exception e){
objectBasicResponse.setMessge(e.getMessage());
}
return objectBasicResponse;
}
public static void main(String[] args) {
new MyRuntimeException(111,"这个参数有误");
}
}
2. 封装统一的响应工具类
package com.monkey;
public class BasicResponse<T>{
int code;
String messge;
T Data;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessge() {
return messge;
}
public void setMessge(String messge) {
this.messge = messge;
}
public T getData() {
return Data;
}
public void setData(T data) {
Data = data;
}
}
边栏推荐
猜你喜欢
随机推荐
[NCTF2019]SQLi-1||SQL注入
10-security登录
MySQL删库不跑路
【7.31】代码源 - 【矩阵操作】【宝箱】【New Stone Game】【等差数列】
【图像分类】2022-MPViT CVPR
8-jwt工具类
11-security认证.md
高并发基石:多线程、守护线程、线程安全、线程同步、互斥锁,一文扫尽!...
Understand the next hop address in the network topology in seconds
向往的生活
FreeRTOS任务管理
微信小程序--》条件与列表渲染以及WXSS模板样式
Flink / Scala - 使用 CountWindow 实现按条数触发窗口
一套开源的可快速搭建自己的物联网/智能家居系统源码
麒麟信安邀您抢先看 | openEuler 志高远,开源汇智创未来-开放原子全球开源峰会欧拉分论坛最详细议程出炉
为什么要使用 playwright 做浏览器自动化测试?
【深度学习】基于tensorflow的小型物体识别训练(数据集:CIFAR-10)
吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(上)
8 个常用的 Wireshark 使用技巧,一看就会
2022/8/2 考试总结









