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

adam-singer picture adam-singer · Dec 20, 2012 · Viewed 14.9k times · Source

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);

Answer

John Evans picture John Evans · Dec 20, 2012

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);
}