自定义异常类
继承runtimeexception可以不处理异常:
package com.example.emos.wx.exception;
import lombok.Data;
@Data
public class EmosException extends RuntimeException{
private String msg;
private int code = 500;
public EmosException(String msg) {
super(msg);
this.msg = msg;
}
public EmosException(String msg, Throwable e) {
super(msg, e);
this.msg = msg;
}
public EmosException(String msg, int code) {
super(msg);
this.msg = msg;
this.code = code;
}
public EmosException(String msg, int code, Throwable e) {
super(msg, e);
this.msg = msg;
this.code = code;
}
}
throw 自定义异常的时候,小程序掉接口响应是500,返回的内容就是throw时写的内容,如 throw new EmosException("绑定超级管理员失败")
浙公网安备 33010602011771号