Added CommandExecutionException which wraps any exception thrown during the execution of command handlers. Should be handled using CommandManager#registerExceptionHandler, similar to NoSuchCommandException, ArgumentParseException, etc.

This commit is contained in:
jmp 2020-11-19 19:50:17 -08:00 committed by Alexander Söderberg
parent 2f0ded5be6
commit 7df6917fe4
14 changed files with 240 additions and 32 deletions

View file

@ -28,6 +28,7 @@ import cloud.commandframework.annotations.injection.ParameterInjectorRegistry;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.flags.FlagContext;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.exceptions.CommandExecutionException;
import cloud.commandframework.execution.CommandExecutionHandler;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -115,8 +116,10 @@ class MethodCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
/* Invoke the command method */
try {
this.methodHandle.invokeWithArguments(arguments);
} catch (final Throwable e) {
e.printStackTrace();
} catch (final Error e) {
throw e;
} catch (final Throwable throwable) {
throw new CommandExecutionException(throwable);
}
}