ExceptionHandler constructor

const ExceptionHandler(
  1. Object value
)

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.

Parameters

  • value: The exception class (or class type wrapper) this handler method should catch.

Implementation

const ExceptionHandler(this.value);