package com.example.demo.common; public class ServiceException extends RuntimeException { private static final long seriaVersionUID = 1L; private String message; @Override public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public ServiceException(final String message) { this.message = message; } public ServiceException(final String message, Throwable th) { super(message, th); this.message = message; } public static void throwEx(String message){ throw new ServiceException(message); } }
@ApiOperation("登录接口") @PostMapping("login") public String login(@RequestBody UserDto userDto){ String result = userService.login(userDto); if(userDto.getName().contains("error2")){ throw new ServiceException("error2",new NullPointerException()); } if(userDto.getName().contains("error")){ ServiceException.throwEx("用户名中含有error"); } return "成功" + result; }
服务端日志
服务端日志
原文:https://www.cnblogs.com/Durant0420/p/15073278.html