Chain class
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 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"
"$stackChain");
});
- Implemented types
Constructors
-
Chain(Iterable<
Trace> traces) -
Returns a new Chain comprised of
traces. - Chain.current([int level = 0])
-
Returns the current stack chain.
factory
- Chain.forTrace(StackTrace trace)
-
Returns the stack chain associated with
trace.factory - Chain.parse(String chain)
-
Parses a string representation of a stack chain.
factory
Properties
Methods
-
foldFrames(
bool predicate(Frame), {bool terse = false}) → Chain -
Returns a new Chain based on this chain where multiple stack frames
matching
predicateare folded together. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
toTrace(
) → Trace - Converts this chain to a Trace.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
capture<
T> (T callback(), {void onError(Object error, Chain)?, bool when = true, bool errorZone = true, Map< Object?, Object?> ? zoneValues}) → T -
If
whenistrue, runscallbackin a Zone in which the current stack chain is tracked and automatically associated with (most) errors. -
disable<
T> (T callback(), {bool when = true}) → T -
If
whenistrueand this is called within a Chain.capture zone, runscallbackin a Zone in which chain capturing is disabled. -
track(
Object? futureOrStream) → dynamic -
Returns
futureOrStreamunmodified.