This commit is contained in:
Andy Clement
2010-05-06 00:26:13 +00:00
parent f53621a86f
commit 2b0655b459
3 changed files with 78 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.expression;
/**
* This exception wraps (as cause) a checked exception thrown by some method that SpEL invokes.
* It differs from a SpelEvaluationException because this indicates the occurrence of a checked exception
* that the invoked method was defined to throw. SpelEvaluationExceptions are for handling (and wrapping)
* unexpected exceptions.
*
* @author Andy Clement
* @since 3.0.3
*/
public class ExpressionInvocationTargetException extends EvaluationException {
public ExpressionInvocationTargetException(int position, String message, Throwable cause) {
super(position, message, cause);
}
public ExpressionInvocationTargetException(int position, String message) {
super(position, message);
}
public ExpressionInvocationTargetException(String expressionString, String message) {
super(expressionString, message);
}
public ExpressionInvocationTargetException(String message, Throwable cause) {
super(message, cause);
}
public ExpressionInvocationTargetException(String message) {
super(message);
}
}

View File

@@ -21,6 +21,7 @@ import java.util.List;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.ExpressionInvocationTargetException;
import org.springframework.expression.MethodExecutor;
import org.springframework.expression.MethodResolver;
import org.springframework.expression.TypedValue;
@@ -123,8 +124,9 @@ public class MethodReference extends SpelNodeImpl {
if (rootCause instanceof RuntimeException) {
throw (RuntimeException)rootCause;
} else {
throw new SpelEvaluationException( getStartPosition(), rootCause, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION,
this.name, state.getActiveContextObject().getValue().getClass().getName(), rootCause.getMessage());
throw new ExpressionInvocationTargetException( getStartPosition(),
"A problem occurred when trying to execute method '"+this.name+"' on object of type '"+state.getActiveContextObject().getValue().getClass().getName()+"'",
rootCause);
}
}
}