commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From germu...@apache.org
Subject svn commit: r178565 - /jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
Date Thu, 26 May 2005 01:48:58 GMT
Author: germuska
Date: Wed May 25 18:48:57 2005
New Revision: 178565

URL: http://svn.apache.org/viewcvs?rev=178565&view=rev
Log:
Catch InvocationTargetException and throw its cause instead, except when the cause is not
an instance of Exception.

Modified:
    jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java

Modified: jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java?rev=178565&r1=178564&r2=178565&view=diff
==============================================================================
--- jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
(original)
+++ jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
Wed May 25 18:48:57 2005
@@ -2,6 +2,8 @@
 
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
+
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.WeakHashMap;
 
@@ -30,7 +32,11 @@
      * returning a boolean value as interpreted by <code>evaluateResult</code>.
      * @param context
      * @return
-     * @throws Exception
+     * @throws IllegalStateException if neither 'method' nor 'methodKey' properties are defined
+     * @throws Exception if any is thrown by the invocation.  Note that if invoking the method
+     * results in an InvocationTargetException, the cause of that exception is thrown instead
of
+     * the exception itself, unless the cause is an <code>Error</code> or other
<code>Throwable</code>
+     * which is not an <code>Exception</code>. 
      */
     public boolean execute(Context context) throws Exception {
 
@@ -40,7 +46,12 @@
 
         Method methodObject = extractMethod(context);
 
-        return evaluateResult(methodObject.invoke(this, getArguments(context)));
+        try {
+            return evaluateResult(methodObject.invoke(this, getArguments(context)));
+        } catch (InvocationTargetException e) {
+            if (e instanceof Exception) throw (Exception) e.getCause();
+            throw e;
+        }
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message