From 3b9d58614f0ad192da8bffa657b820c28cdaa1ef Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 23 Sep 2014 21:44:50 +0200 Subject: [PATCH] Adds proper exception handling during calling action This will allow ExceptionHandler to work --- .../xwork2/DefaultActionInvocation.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java index 4539e56b8..dd44b140e 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java @@ -28,6 +28,8 @@ import com.opensymphony.xwork2.util.ValueStackFactory; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; import com.opensymphony.xwork2.util.profiling.UtilTimerStack; +import ognl.MethodFailedException; +import ognl.NoSuchPropertyException; import ognl.OgnlException; import java.util.ArrayList; @@ -439,17 +441,23 @@ public class DefaultActionInvocation implements ActionInvocation { } } return saveResult(actionConfig, methodResult); - } catch (OgnlException e) { + } catch (NoSuchPropertyException e) { + throw new IllegalArgumentException("The " + methodName + "() is not defined in action " + getAction().getClass() + ""); + } catch (MethodFailedException e) { // We try to return the source exception. - //Throwable t = e.getTargetException(); + Throwable t = e.getCause(); if (actionEventListener != null) { - String result = actionEventListener.handleException(e, getStack()); + String result = actionEventListener.handleException(t, getStack()); if (result != null) { return result; } } - throw e; + if (t instanceof Exception) { + throw (Exception) t; + } else { + throw e; + } } finally { UtilTimerStack.pop(timerKey); }