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 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
- terse → Chain
-
Returns a terser version of this. [...]
read-only
-
traces
→ List<
Trace> -
The stack traces that make up this chain. [...]
final
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
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. [...] -
toString(
) → String -
Returns a string representation of this object.
override
-
toTrace(
) → Trace - Converts this to a Trace. [...]
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited
Static Methods
-
capture<
T>( T callback(), { void onError(dynamic error, Chain 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+.")