endypark 2017-09-19 06:42 采纳率: 0%
浏览 1289

自定义的AppException imp Runtime, 抛出时被包装了NestedServlet

自定义的AppException implements RuntimeException, 在抛出时被包装了NestedServletException,这样就无法被 catche(AppException ae)捕捉到,只能被Exception捕捉到。。。有没有办法,不让随便“被包装”,而是我抛什么就是什么。

有个方案是 catch exception e,然后再 e.getRootCause ,但是这样,无法 使用catch AppException ae,只能 catch Exception e,然后再做if判断,感觉这样不爽。

  • 写回答

1条回答

  • 淡淡的id 2020-03-06 17:21
    关注
    if (e instanceof NestedServletException) {//加了spring security就被包装成这个exception了
                if (((NestedServletException) e).getRootCause() instanceof BizException) {
                    logger.error(e.getClass().getName(), e);
                    result = ResultUtils.errorResult(((BizException) ((NestedServletException) e).getRootCause()).getCode(),
                            ((NestedServletException) e).getRootCause().getLocalizedMessage());
                } else {
                    logger.error(" error ", e);
                    // TODO 未知的异常,应该格外注意,可以发送邮件通知等
                    result = ResultUtils.serverError();
                }
            } 
    

    BizException只是简单继承只runtimeexception而已

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制