在struts的action中throw exception却没有打印到控制台
来源:互联网 发布:足彩数据分析 编辑:程序博客网 时间:2024/06/05 09:06
在struts的action中throw exception却没有打印到控制台
问题: 在struts的action中throw出来的异常,在jsp上显示了,但是没有打印到控制台。
结论:先说下吧,到最后还是没有找出来为什么没有打印异常。
下面是寻找为什么打印的过程,一步一步自己还是学到了一些东西。
JVM为什么能打印出来我们throw出来的异常。
我们在类中抛出来的异常,如果没有指定uncaughtExceptionHandler,则默认调用ThreadGroup的uncaughtException的方法,先去找parent group,如果存在就继续向上走。如果没有parent了,还是没有这种类型异常的处理器,那么就是打印到system.err中.Called by the Java Virtual Machine when a thread in this thread group stops because of an uncaught exception, and the thread does not have a specific Thread.UncaughtExceptionHandler installed.
The uncaughtException method of ThreadGroup does the following:
If this thread group has a parent thread group, the uncaughtException method of that parent is called with the same two arguments.
Otherwise, this method checks to see if there is a default uncaught exception handler installed, and if so, its uncaughtException method is called with the same two arguments.
Otherwise, this method determines if the Throwable argument is an instance of ThreadDeath. If so, nothing special is done. Otherwise, a message containing the thread’s name, as returned from the thread’s getName method, and a stack backtrace, using the Throwable’s printStackTrace method, is printed to the standard error stream.
Applications can override this method in subclasses of ThreadGroup to provide alternative handling of uncaught exceptions.Specified by: uncaughtException(…) in UncaughtExceptionHandler
Parameters:- t the thread that is about to exit.
- e the uncaught exception.
那么Struts对抛出来的异常是怎么处理的呢?
从开始调用,进入ExceptionMappingInterceptor拦截器- 首先try catch捕捉到异常
- 在catch过程中处理,查看是否设置了打印异常及级别;如果设置了就打印异常。
- 将exception根据配置匹配并跳转到特定的global error页面
- 如果匹配结果为空,那么就throw e
- 关键这里也没有进入ThreadGroup的uncaughtException方法,这就很奇怪了
总结一下:
- 我在ThreadGroup中打了断点,普通的main可以进去,但是action抛出来的进不去。
- 不是log4j或者其他引起的,因为断点都没进
- 在action中e.printStacktrace()可以成功打印异常,显示调用printStacktrace(System.err)
推测:
action抛出来的异常不能被ThreadGroup的uncaughtException处理,可能有设置过默认的default uncaughtException handler,也可能不让默认的进行处理。希望有知道的可以给我讲解一下.
解决办法:
- 显示调用e.printStackStrace
- 配置exceptionInterceptor
- 将action抛出来的异常,整体进行一层的捕获,形成更友好的信息。
- 在struts的action中throw exception却没有打印到控制台
- 在catch块中throw new Exception的意义
- 在catch块中throw new Exception的意义 .
- Java中"throw new Exception() "和"new Exception()"的区别
- java Exception出错的栈信息打印到日志中
- Struts中JSP到Action过程中数组的投射
- 在Struts action中利用.do跳转到另一action传值方法
- J2EE开发中遇见的Exception(java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet)
- 在Struts的action中访问serverle的API
- 在Struts2 中 struts.xml的Action配置详解
- struts 在action中获取用户提交的参数。
- 在Struts的action中使用Jdom生成xml文件
- catch块中throw new Exception的意义
- java Exception 出错的栈信息打印到日志中 打印堆栈信息
- java Exception 出错的栈信息打印到日志中 打印堆栈信息
- 使用Spring内置拦截器为Struts的Action在每个方法调用之前打印一句话
- Struts中Action的种类
- struts 中 action 的重用
- JDBC连接数据库操作(三)
- Stack/Queue与Vector/List的联系
- Matlab代码从Windows拷贝到Linux变成乱码
- 机器学习的种类及其典型的任务
- 解决CentOS sudo提示用户不在sudoers文件中的方法
- 在struts的action中throw exception却没有打印到控制台
- UVC 摄像头驱动(三)配置摄像头,实时数据采集
- 有关TLD源码的使用过程介绍
- 1125
- 数据库的一些常见面试题及其答案详解
- usaco-Calf Flac 最长的回文
- Android界面资源汇总
- 浏览器被劫持怎么办?
- C#语法小知识(二十)params