Interface ExceptionHandler
ExceptionCatch.
Implementations can be registered as beans and referenced by name in the @ExceptionCatch annotation.
What handleException throwing actually does: anything it throws propagates to the
caller of the intercepted method, including a checked Throwable the intercepted method's
own throws clause does not declare - ExceptionInterceptor
does not catch or wrap it. There is no distinction between a handler that deliberately
re-threw and one whose body failed by accident: both reach business code the same way. A handler
implementation that assumes an accidental failure falls back to the annotation's default value is
wrong about this interface's contract - write handleException bodies with that in mind, or
catch what you do not want to propagate before it leaves this method.
The annotation's default value (@ExceptionCatch(defaultValue = ...)) is used only when
no handler is configured, the configured handler bean name cannot be resolved from the container,
or the resolved bean does not implement this interface. Once a handler runs, the value
handleException returns (including null) is used as the intercepted method's
result without consulting the default value.
Self-invocation: a call a bean makes to its own method is intercepted here exactly as an
external call is - this codebase's proxy is instantiated directly as the bean (there is no
separate delegate target instance), so self-invocation is not the AOP-bypass gap it is for a
delegating proxy. See ProxyFactory's class javadoc.
- Since:
- 6.2.0
- Author:
- wisdomme
-
Method Summary
Modifier and TypeMethodDescriptiondefault intgetOrder()Gets the order of this handler.handleException(Throwable exception, Object target, Method method, Object[] args) Handles an exception caught during method execution.default booleanDetermines if this handler supports handling the given exception type.
-
Method Details
-
handleException
Object handleException(Throwable exception, Object target, Method method, Object[] args) throws Throwable Handles an exception caught during method execution.Whatever this method throws - checked or unchecked, declared on the intercepted method or not - propagates to the caller unconditionally. See the interface javadoc for the full semantics, including why a handler failure and a deliberate re-throw are indistinguishable.
- Parameters:
exception- the exception that was caughttarget- the target object whose method threw the exceptionmethod- the method that threw the exceptionargs- the arguments passed to the method- Returns:
- the value the intercepted method returns to its caller, used as is (including
null) and never replaced by the annotation's default value; it must be assignable to the method's return type - Throws:
Throwable- if the handler decides to re-throw the exception, or if the handler's own body fails - both propagate identically, see the interface javadoc
-
supports
Determines if this handler supports handling the given exception type. This is consulted only for global handlers passed toExceptionInterceptor; a handler named in@ExceptionCatch(handler = ...)is called without this check.- Parameters:
exceptionType- the type of exception- Returns:
- true if this handler can handle the exception
-
getOrder
default int getOrder()Gets the order of this handler. The framework does not use this value; global handlers are tried in list order.- Returns:
- the handler order
-