AfterThrowing class

Marks an aspect method to run after each matched call that threw, with the error.

Use it to log or count failures. The parameter named throwing receives the error; without it, the first parameter that is neither the JoinPoint nor bound by the pointcut does. The parameter's type filters: the advice runs only for errors of that type. The error is always rethrown afterwards, so the caller still sees it. For a method returning a Future, it runs when the future fails.

// Logs UnsupportedErrors of the Calculator; other errors pass by.
@AfterThrowing('execution(* Calculator.*(..))')
void failed(JoinPoint joinPoint, UnsupportedError error) =>
    log.add('${joinPoint.signature.name} failed: $error');

Spring (Java):

@AfterThrowing(
    pointcut = "execution(* Calculator.*(..))", throwing = "error")
void failed(JoinPoint joinPoint, UnsupportedOperationException error) {
  log.add(joinPoint.getSignature().getName() + " failed: " + error);
}

Constructors

AfterThrowing(String pointcut, {String? throwing})
Runs the annotated method after calls matching pointcut throw.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
pointcut → String
The pointcut expression selecting the advised methods.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
throwing → String?
The name of the advice parameter that receives the error; null picks the first parameter that is neither the JoinPoint nor bound by the pointcut.
final

Methods

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