织梦 图片网站源码,wordpress+显示异常,广州天河区是富人区吗,商城网站建设运营协议书记录一个我遇到得问题
问题描述
我本来使用AOP切面来进行全局异常管理#xff0c;但是使用AOP之后fxml中通过fx:id绑定得参数无法被注入
Slf4j
Component
Aspect
public class GlobalExceptionAspect {AfterThrowing(pointcut execution(* com.shkj.videoclassifica…记录一个我遇到得问题
问题描述
我本来使用AOP切面来进行全局异常管理但是使用AOP之后fxml中通过fx:id绑定得参数无法被注入
Slf4j
Component
Aspect
public class GlobalExceptionAspect {AfterThrowing(pointcut execution(* com.shkj.videoclassification..*(..)), throwing ex)public void handleServiceException(Exception ex) {// 处理异常逻辑
// System.err.println(Caught an exception in service layer: ex.getMessage());
// ex.printStackTrace();log.error(ex.getMessage());AlertUtils.showAlert(系统错误,ex.getMessage());}
}解决办法
不使用全局异常处理集合使用try catch捕获异常进行处理
Component
Slf4j
public class GlobalExceptionHandler {public static void handleException(Exception ex) {// 使用 Platform.runLater 确保在 JavaFX 线程中安全地显示弹窗Platform.runLater(() - {log.error(ex.getMessage());AlertUtils.showAlert(系统错误, ex.getMessage());});}
}
手动触发异常 FXMLpublic void initialize() {try {System.out.println(初始化);System.out.println(labelMsg);throw new CheckedException(初始化失败);} catch (Exception e) {GlobalExceptionHandler.handleException(e);}}