Skip to content

Commit

Permalink
Handle exceptions thrown from bindings as a convertible InvocationTar…
Browse files Browse the repository at this point in the history
…getException.

For example, if IncompleteRegionException is thrown by a binding, it
will result in a InvocationTargetException now with a getCause(),
which gets handled as if that exception was thrown from the actual
Method that is invoked for the command.
  • Loading branch information
sk89q committed Jul 1, 2014
1 parent 11d37bc commit 08ad5f4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.sk89q.worldedit.util.command.binding.PrimitiveBindings;
import com.sk89q.worldedit.util.command.binding.StandardBindings;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.util.List;

Expand Down Expand Up @@ -77,8 +78,8 @@ public interface Binding {
* @throws ParameterException thrown if the parameter could not be formulated
* @throws CommandException on a command exception
*/
Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume)
throws ParameterException, CommandException;
Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume)
throws ParameterException, CommandException, InvocationTargetException;

/**
* Get a list of suggestions for the given parameter and user arguments.
Expand Down
Expand Up @@ -143,7 +143,7 @@ public BindingBehavior getBehavior(ParameterData parameter) {

@Override
public Object bind(ParameterData parameter, ArgumentStack scoped,
boolean onlyConsume) throws ParameterException, CommandException {
boolean onlyConsume) throws ParameterException, CommandException, InvocationTargetException {
BoundMethod binding = match(parameter);
List<Object> args = new ArrayList<Object>();
args.add(scoped);
Expand Down Expand Up @@ -178,7 +178,7 @@ public Object bind(ParameterData parameter, ArgumentStack scoped,
} else if (e.getCause() instanceof CommandException) {
throw (CommandException) e.getCause();
}
throw new RuntimeException(e.getCause());
throw e;
}
}

Expand Down
Expand Up @@ -366,8 +366,8 @@ private boolean mayConsumeArguments(int i, ContextArgumentStack scoped) {
* @throws ParameterException on an error
* @throws CommandException on an error
*/
private Object getDefaultValue(int i, ContextArgumentStack scoped)
throws ParameterException, CommandException {
private Object getDefaultValue(int i, ContextArgumentStack scoped)
throws ParameterException, CommandException, InvocationTargetException {
CommandContext context = scoped.getContext();
ParameterData parameter = parameters[i];

Expand Down

0 comments on commit 08ad5f4

Please sign in to comment.