Annotation Interface ExceptionCatch
Annotation to mark methods or classes for automatic exception catching.
When a method annotated with @ExceptionCatch throws an exception of the specified type, it will be caught and handled by the AOP framework instead of propagating up.
Usage example:
@Service
public class UserService {
@ExceptionCatch(value = {NullPointerException.class, IllegalArgumentException.class})
public User findUser(String id) {
return userRepository.findById(id);
// If NPE or IAE is thrown, it will be caught and null returned
}
@ExceptionCatch(silent = true)
public void logAction(String action) {
// Any exception will be silently caught without logging
}
}
- Since:
- 6.2.0
- Author:
- wisdomme
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionA default value expression to return when an exception is caught.The name of a custom exception handler bean to use.booleanWhether to silently catch exceptions without logging.The exception types to catch.
-
Element Details
-
value
The exception types to catch.Defaults to catching all exceptions (
Exception).- Returns:
- the exception types to catch
- Default:
{java.lang.Exception.class}
-
silent
boolean silentWhether to silently catch exceptions without logging.When false (default), caught exceptions will be logged as warnings. When true, exceptions are silently swallowed.
- Returns:
- true if exceptions should be caught silently
- Default:
false
-
handler
String handlerThe name of a custom exception handler bean to use.If specified, the handler bean must implement
ExceptionHandler. The handler will be retrieved from the container by this name.- Returns:
- the name of the exception handler bean, or empty string for default handling
- Default:
""
-
defaultValue
String defaultValueA default value expression to return when an exception is caught.Supports simple expressions:
- "null" - returns null
- "true" or "false" - returns boolean
- Numeric literals - returns the number
- "empty" - returns empty collection/array/string
If not specified, the method's return type default value is used (null for objects, 0 for numbers, false for boolean).
- Returns:
- the default value expression
- Default:
""
-