Struts2exception处理用法?
我有下面的Action
类,其中getTspNameIdMap
抛出ReqMgmtException
exception(自定义exception)。
public String findTspNameIdMap(){ SlsReqMgmtCommonRemote slsReqMgmtCommonRemote = null; tspNameIdMap = new HashMap(); try{ slsReqMgmtCommonRemote = getSlsReqMgmtCommonRemote(); tspNameIdMap = slsReqMgmtCommonRemote.getTspNameIdMap(gmaThresholdParameters.getId().getCircleId()); } catch(ReqMgmtException rEx){ addActionError(rEx.getError()); result = "error"; return ERROR; } catch (Exception e){ addActionError("Error in processing your request. Contact Administrator"); e.printStackTrace(); System.out.println("[ConfigureTspThresholdAction: findTspNameIdMap Function]:In catch Inside Constructor!!"); result = "error"; return ERROR; } return SUCCESS; }
我知道Struts2中也存在exception处理,但是目前我还没有使用它。 我应该使用Struts2exception处理吗? 它的用途是什么?
你应该在Struts2中使用exception处理机制,这就是拦截器提供的exception
。 您还应该像处理问题一样处理动作方法中的exception。 如果它处理好所有exception,如果不是exception处理程序可以处理它。 此外,在一些没有throws Exception
签名的方法中,您只能捕获exception但不能返回ERROR
结果。 因此,重新抛出exception并通过拦截器处理它是一种解决方法。
参考文献:
- struts2和hibernate中的exception处理
- 在struts xml中声明/处理哪些exception
- Struts 2当用户插入不存在的动作时该怎么做
- 如何validation使用struts2 json插件发送的json而不抛出exception
- 在我输入finally块之前是否可以检测是否发生了exception?
- Jax-RS(Jersey)上下文中的WebApplicationException和WebServiceException之间的区别
- 什么是来自.net的java等效的AggregateException?
- @ControllerAdvice优于@ExceptionHandler或HandlerExceptionResolver处理exception的优点是什么?
- 在java中使用assert有什么用
- 捕获更一般类型的exception是否好?
- 有关多次“捕获”的问题
- JAX-WS Soap错误没有出现在WSDL中
- 处理Spring中过滤引发的exception