A chain of stack traces.

A stack chain is a collection of one or more stack traces that collectively represent the path from main through nested function calls to a particular code location, usually where an error was thrown. Multiple stack traces are necessary when using asynchronous functions, since the program's stack is reset before each asynchronous callback is run.

Stack chains can be automatically tracked using Chain.capture. This sets up a new Zone in which the current stack chain is tracked and can be accessed using new Chain.current. Any errors that would be top-leveled in the zone can be handled, along with their associated chains, with the onError callback. For example:

Chain.capture(() {
  // ...
}, onError: (error, stackChain) {
  print("Caught error $error\n"
  • StackTrace

Static Methods

capture(dynamic callback(), {void onError(error, Chain chain), bool when: true}) → dynamic

If when is true, runs callback in a Zone in which the current stack chain is tracked and automatically associated with (most) errors.

track(futureOrStream) → dynamic

Returns futureOrStream unmodified.


Chain(Iterable<Trace> traces)

Returns a new Chain comprised of traces.

Chain.current([int level = 0])

Returns the current stack chain.

Chain.forTrace(StackTrace trace)

Returns the stack chain associated with trace.

Chain.parse(String chain)

Parses a string representation of a stack chain.



hashCode → int

Get a hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited
terse Chain

Returns a terser version of this.

traces → List<Trace>

The stack traces that make up this chain.



operator ==(other) → bool

The equality operator.



foldFrames(bool predicate(Frame frame), {bool terse: false}) Chain

Returns a new Chain based on this where multiple stack frames matching predicate are folded together.

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

toString() → String

Returns a string representation of this object.

toTrace() Trace

Converts this to a Trace.