How do you get the current stacktrace in Dart for a Completer.CompleteException(exception, stackTrace);

DartDart Async

Dart Problem Overview


If some code returns a future and determines that the future should return "Error" or "Exception" how can a stack trace be passed to Completer.completeException(exception, stackTrace);

Dart Solutions


Solution 1 - Dart

If you're not in a catch block, you can use StackTrace.current

Solution 2 - Dart

If I understand correctly: when you catch an exception in dart, you can also catch the stack trace:

try {
  // something
} catch(e, stacktrace) {
  myCompleter.completeException(e, stacktrace);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionadam-singerView Question on Stackoverflow
Solution 1 - DartcambunctiousView Answer on Stackoverflow
Solution 2 - DartJohn EvansView Answer on Stackoverflow