Package revxrsal.commands.exception
Class CommandExceptionAdapter
java.lang.Object
revxrsal.commands.exception.CommandExceptionAdapter
- All Implemented Interfaces:
CommandExceptionHandler
- Direct Known Subclasses:
DefaultExceptionHandler
An implementation of
CommandExceptionHandler
that inlines all exceptions
into individual, overridable methods. This greatly simplifies the process
of handling exceptions.
This class loosely uses reflections to find the appropriate handler method. To handle custom exceptions, extend this class and define a method that meets the following criteria:
- Method is public
- Method has 2 parameters, one is a CommandActor (or a subclass of it), and the other is your exception. The name of the method, and the order of parameters does not matter.
An example:
public void onCustomException(CommandActor actor, CustomException e) {
actor.error("Caught you!");
}
If you have methods that meet the above criteria and want the reflection handler
to ignore them, annotate them with CommandExceptionAdapter.Ignore
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
An annotation to automatically ignore any method that may otherwise be a handler method. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
argumentParse
(@NotNull CommandActor actor, @NotNull ArgumentParseException exception) void
commandInvocation
(@NotNull CommandActor actor, @NotNull CommandInvocationException exception) void
cooldown
(@NotNull CommandActor actor, @NotNull CooldownException exception) void
handleException
(@NotNull Throwable throwable, @NotNull CommandActor actor) Handles the given exception.void
invalidBoolean
(@NotNull CommandActor actor, @NotNull InvalidBooleanException exception) void
invalidCommand
(@NotNull CommandActor actor, @NotNull InvalidCommandException exception) void
invalidEnumValue
(@NotNull CommandActor actor, @NotNull EnumNotFoundException exception) void
invalidHelpPage
(@NotNull CommandActor actor, @NotNull InvalidHelpPageException exception) void
invalidNumber
(@NotNull CommandActor actor, @NotNull InvalidNumberException exception) void
invalidSubcommand
(@NotNull CommandActor actor, @NotNull InvalidSubcommandException exception) void
invalidURL
(@NotNull CommandActor actor, @NotNull InvalidURLException exception) void
invalidUUID
(@NotNull CommandActor actor, @NotNull InvalidUUIDException exception) void
missingArgument
(@NotNull CommandActor actor, @NotNull MissingArgumentException exception) void
noPermission
(@NotNull CommandActor actor, @NotNull NoPermissionException exception) void
noSubcommandSpecified
(@NotNull CommandActor actor, @NotNull NoSubcommandSpecifiedException exception) void
numberNotInRange
(@NotNull CommandActor actor, @NotNull NumberNotInRangeException exception) void
onUnhandledException
(@NotNull CommandActor actor, @NotNull Throwable throwable) void
sendableException
(@NotNull CommandActor actor, @NotNull SendableException exception) void
tooManyArguments
(@NotNull CommandActor actor, @NotNull TooManyArgumentsException exception)
-
Constructor Details
-
CommandExceptionAdapter
public CommandExceptionAdapter()
-
-
Method Details
-
onUnhandledException
public void onUnhandledException(@NotNull @NotNull CommandActor actor, @NotNull @NotNull Throwable throwable) -
missingArgument
public void missingArgument(@NotNull @NotNull CommandActor actor, @NotNull @NotNull MissingArgumentException exception) -
invalidEnumValue
public void invalidEnumValue(@NotNull @NotNull CommandActor actor, @NotNull @NotNull EnumNotFoundException exception) -
invalidUUID
public void invalidUUID(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidUUIDException exception) -
invalidNumber
public void invalidNumber(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidNumberException exception) -
invalidURL
public void invalidURL(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidURLException exception) -
invalidBoolean
public void invalidBoolean(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidBooleanException exception) -
numberNotInRange
public void numberNotInRange(@NotNull @NotNull CommandActor actor, @NotNull @NotNull NumberNotInRangeException exception) -
noPermission
public void noPermission(@NotNull @NotNull CommandActor actor, @NotNull @NotNull NoPermissionException exception) -
argumentParse
public void argumentParse(@NotNull @NotNull CommandActor actor, @NotNull @NotNull ArgumentParseException exception) -
commandInvocation
public void commandInvocation(@NotNull @NotNull CommandActor actor, @NotNull @NotNull CommandInvocationException exception) -
tooManyArguments
public void tooManyArguments(@NotNull @NotNull CommandActor actor, @NotNull @NotNull TooManyArgumentsException exception) -
invalidCommand
public void invalidCommand(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidCommandException exception) -
invalidSubcommand
public void invalidSubcommand(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidSubcommandException exception) -
noSubcommandSpecified
public void noSubcommandSpecified(@NotNull @NotNull CommandActor actor, @NotNull @NotNull NoSubcommandSpecifiedException exception) -
cooldown
public void cooldown(@NotNull @NotNull CommandActor actor, @NotNull @NotNull CooldownException exception) -
invalidHelpPage
public void invalidHelpPage(@NotNull @NotNull CommandActor actor, @NotNull @NotNull InvalidHelpPageException exception) -
sendableException
public void sendableException(@NotNull @NotNull CommandActor actor, @NotNull @NotNull SendableException exception) -
handleException
public void handleException(@NotNull @NotNull Throwable throwable, @NotNull @NotNull CommandActor actor) Description copied from interface:CommandExceptionHandler
Handles the given exception. Note that this method does not provide information about the command context (such as the command, etc.) These are available in individual exceptions and can be accessed only if the thrown exception exposes them.- Specified by:
handleException
in interfaceCommandExceptionHandler
- Parameters:
throwable
- Exception to handleactor
- The command actor
-