Consider code like this:
import 'dart:async';
foo() {
new Timer(onesec, bar);
}
bar() {
throw "from bar";
}
const onesec = const Duration(seconds:1);
main() {
runZoned(() {
new Timer(onesec, foo);
},
onError: (e, stackTrace) => print(stackTrace));
}
How can I tell that bar
was "called" by foo
in the stackTrace
that I print out?
I'd like to see something like:
bar
...
foo
...
main
Asynchronous stack traces allow you to inspect function calls beyond the current event loop. This is particularly useful because you can examine the scope of previously executed frames that are no longer on the event loop. This feature is currently an experiment and needs to be enabled.
A full stack trace allows you to see the chain of files from when your custom tag reached your set breakpoint. If you click on any of the pages in the caller chain then FusionDebug will show you that page and will highlight the line at which the next page in the chain was called.
Get a Stack Trace Using the Thread Class We can obtain a stack trace from a thread by calling the getStackTrace() method on the Thread instance. It returns an array of StackTraceElement, from which details about stack frames of the thread can be found.
A StackTrace is intended to convey information to the user about the call sequence that triggered an exception. These objects are created by the runtime, it is not possible to create them programmatically.
Have a look at the stack_trace package. It uses zones to keep track of asynchronous callbacks. Capturing stack traces for every asynchronous callback is expensive, but for debugging it is definitely worth it.
Example output from the package:
http://dartlang.org/foo/bar.dart 10:11 Foo.<fn>.bar
http://dartlang.org/foo/baz.dart Foo.<fn>.bar
===== asynchronous gap ===========================
http://dartlang.org/foo/bang.dart 10:11 Foo.<fn>.bar
http://dartlang.org/foo/quux.dart Foo.<fn>.bar
According to the doc, the easiest way to get these traces is to use Chain.capture
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With