95

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

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
adam-singer
  • 4,489
  • 4
  • 21
  • 25

2 Answers2

188

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);
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
John Evans
  • 6,858
  • 4
  • 28
  • 26
173

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

cambunctious
  • 8,391
  • 5
  • 34
  • 53
  • 15
    This is useful if you need to get a stack trace from any arbitrary location, but if you're within a `catch` block, the chosen answer is better since Dart already provides a `StackTrace` to you. – Abion47 Jan 29 '19 at 21:26