ExceptionHandler class

Annotation used to mark a method as an exception handler within a controller.

This annotation tells the framework that the decorated method should be invoked when the specified exception type (or its subclass) is thrown during request processing.

Example

@ExceptionHandler(UsernameNotFoundException)
ResponseBody<String> handleUserNotFound(UsernameNotFoundException ex) {
  return ResponseBody.status(HttpStatus.notFound, body: 'User not found');
}

@ExceptionHandler([ClassType<UserException>()])
ResponseBody<String> handleUserException(UserException ex) {
  return ResponseBody.status(HttpStatus.badRequest, body: ex.message);
}

Features

  • Supports passing either a type literal (e.g., MyException) or a ClassType<T> reference.
  • Integrated with JetLeaf's reflection system via ReflectableAnnotation.
  • Implements structural equality through EqualsAndHashCode.

Usage context

  • Target: methods only (@Target({TargetKind.method}))
  • Commonly used in controller or service classes to centralize exception handling.
Annotations
  • @Target.new({TargetKind.method})

Constructors

ExceptionHandler(Object value)
Annotation used to mark a method as an exception handler within a controller.
const

Properties

annotationType Type
Returns the annotation type for reflection purposes.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value Object
The exception type that this method handles.
final

Methods

equalizedProperties() List<Object?>
Returns the list of properties used for equality comparison.
equals(Object other) bool
Checks whether the given object is logically equivalent to this annotation.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Returns a string representation of this annotation.

Operators

operator ==(Object other) bool
The equality operator.
inherited