异常处理
//获取异常发生所在的类名、方法名、行数
1 @RestControllerAdvice 2 @Slf4j 3 public class GlobalException { 4 @ExceptionHandler(XXXException.class) 5 public String serviceExceptionHandler(XXXException e) { 6 StackTraceElement stackTraceElement = e.getStackTrace()[0]; 7 // 获取类名 8 String className = stackTraceElement.getClassName(); 9 String filePath = stackTraceElement.getFileName(); 10 int lineNumber = stackTraceElement.getLineNumber(); 11 String methodName = stackTraceElement.getMethodName(); 12 log.info("类名:{},文件路径:{},行数:{},方法名:{}", className, filePath , lineNumber, methodName); 13 return "类名:" + className + ",文件路径:" + filePath + ",行数:" + lineNumber + "方法名:" + methodName; 14 } 15 }