AfterThrowingInterceptor class abstract interface

An interceptor triggered when a target method throws an exception.

Used primarily for:

  • Centralized error handling
  • Logging and diagnostics
  • Transaction rollback or cleanup

Invocation Order

  1. The target method throws an exception.
  2. afterThrowing is invoked with the error and its StackTrace.

Example

class ErrorLoggerInterceptor implements AfterThrowingInterceptor {
  @override
  bool canIntercept(Method method) => true;

  @override
  void afterThrowing<T>(
    MethodInvocation<T> invocation,
    Object exception,
    Class exceptionClass,
    StackTrace stackTrace,
  ) {
    print("Error in ${invocation.method.getName()}: $exception");
  }
}

See Also

Implemented types

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

afterThrowing<T>(MethodInvocation<T> invocation, Object exception, Class exceptionClass, StackTrace stackTrace) FutureOr<void>
Executed when a target method throws an exception.
canIntercept(Method method) bool
Determines whether this interceptor can intercept the specified method.
inherited
equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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