Interface ExceptionHandler<C,T extends Throwable>
- Type Parameters:
C- the command sender typeT- the exception type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Handles an exception thrown during command parsing & execution.
-
Method Summary
Modifier and TypeMethodDescriptionvoidhandle(@NonNull ExceptionContext<C, T> context) Handles the exception in the givencontext.static <C,T extends Throwable>
@NonNull ExceptionHandler<C, T> Returns an exception handler that does nothing.static <C,T extends Throwable>
@NonNull ExceptionHandler<C, T> Returns an exception handler that re-throws theExceptionContext.exception().static <C,T extends Throwable>
@NonNull ExceptionHandler<C, T> passThroughHandler(@NonNull Consumer<ExceptionContext<C, T>> consumer) Returns an exception handler that re-throws theExceptionContext.exception()after invoking the givenconsumer.static <C,T extends Throwable>
@NonNull ExceptionHandler<C, T> Returns an exception handler that throws the cause of theExceptionContext.exception()if it's notnull.static <C,T extends Throwable>
@NonNull ExceptionHandler<C, T> unwrappingHandler(@NonNull Class<? extends Throwable> causeClass) Returns an exception handler that throws the cause of theExceptionContext.exception()if it's and instance ofcauseClass.static <C,T extends Throwable>
@NonNull ExceptionHandler<C, T> unwrappingHandler(@NonNull Predicate<Throwable> predicate) Returns an exception handler that throws the cause of theExceptionContext.exception()if it's notnulland thepredicateevaluates totrue.
-
Method Details
-
noopHandler
Returns an exception handler that does nothing.- Type Parameters:
C- the command sender typeT- the exception type- Returns:
- the exception handler
-
passThroughHandler
Returns an exception handler that re-throws theExceptionContext.exception().This will allow other exception handlers to handle the exception.
- Type Parameters:
C- the command sender typeT- the exception type- Returns:
- the exception handler
-
passThroughHandler
static <C,T extends Throwable> @NonNull ExceptionHandler<C,T> passThroughHandler(@NonNull Consumer<ExceptionContext<C, T>> consumer) Returns an exception handler that re-throws theExceptionContext.exception()after invoking the givenconsumer.- Type Parameters:
C- the command sender typeT- the exception type- Parameters:
consumer- the consumer- Returns:
- the exception handler
-
unwrappingHandler
static <C,T extends Throwable> @NonNull ExceptionHandler<C,T> unwrappingHandler(@NonNull Predicate<Throwable> predicate) Returns an exception handler that throws the cause of theExceptionContext.exception()if it's notnulland thepredicateevaluates totrue. Otherwise, it will re-throw theExceptionContext.exception().- Type Parameters:
C- the command sender typeT- the exception type- Parameters:
predicate- predicate that tests the cause of the exception- Returns:
- the exception handler
-
unwrappingHandler
static <C,T extends Throwable> @NonNull ExceptionHandler<C,T> unwrappingHandler(@NonNull Class<? extends Throwable> causeClass) Returns an exception handler that throws the cause of theExceptionContext.exception()if it's and instance ofcauseClass. Otherwise, it will re-throw theExceptionContext.exception().- Type Parameters:
C- the command sender typeT- the exception type- Parameters:
causeClass- the type of the cause- Returns:
- the exception handler
-
unwrappingHandler
Returns an exception handler that throws the cause of theExceptionContext.exception()if it's notnull. Otherwise, it will re-throw theExceptionContext.exception().- Type Parameters:
C- the command sender typeT- the exception type- Returns:
- the exception handler
-
handle
Handles the exception in the givencontext.Any exception thrown by the handler will be handled by the
ExceptionController.If the
ExceptionContext.exception()is re-thrown, then the next exception handler in line will get to handle the exception instead.
-