Skip to content

75 Interceptor entry and exit ​

before runs before the function body and after runs when the invocation completes. completion.succeeded() reports whether the intercepted call completed normally.

norm
import std.annotation.FunctionInterceptor
import std.annotation.SourceRetention

annotation Trace implements FunctionInterceptor, SourceRetention {
  Void before(FunctionContext context) { printLine("before") }
  Void after(FunctionContext context, FunctionCompletion completion) {
    printLine("after: ${completion.succeeded()}")
  }
}

@Trace()
String greet() {
  printLine("body")
  return "Norm"
}

main() { printLine(greet()) }

Expected output:

text
before
body
after: true
Norm

Try it: Make greet throw and observe the completion state.

Precise rules: Reference.

Norm 0.25