Chain class Null safety
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"
"$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 where multiple stack frames matching
predicate
are folded together. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
toTrace(
) → Trace - Converts this 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}) → T -
If
when
istrue
, runscallback
in 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
when
istrue
and this is called within a Chain.capture zone, runscallback
in a Zone in which chain capturing is disabled. -
track(
dynamic futureOrStream) → dynamic -
Returns
futureOrStream
unmodified.Deprecated('Chain.track is not necessary in Dart 1.7+.')">@Deprecated('Chain.track is not necessary in Dart 1.7+.')