JAVA后台捕获异常,返回异常信息到前端

1.编写自己捕获异常的包装类

JAVA后台捕获异常,返回异常信息到前端_第1张图片

标注绿色的是自己最近写的包装类

BusinessExceptionNew 类

package com.aostar.trade.common.ExceptionHandler;

import lombok.Data;

/**
 * @author jay
 * @Description: 自定义业务异常类
 * @date 2021/6/23 14:58
 */
@Data
public class BusinessExceptionNew extends RuntimeException {
    /**
     * 错误编码
     */
    private String code;
    public BusinessExceptionNew() {
        super();
    }
    public BusinessExceptionNew(String message) {
        super(message);
    }
    public BusinessExceptionNew(String code, String message) {
        super(message);
        this.code = code;
    }
    public BusinessExceptionNew(Throwable cause) {
        super(cause);
    }
    public BusinessExceptionNew(String message, Throwable cause) {
        super(message, cause);
    }
    public BusinessExceptionNew(String message, Throwable cause,
                                boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Override
    public String getMessage() {
  

你可能感兴趣的:(面试,学习路线,阿里巴巴,android,前端,后端)