Trace.parse constructor

Trace.parse(String trace)

Parses a string representation of a stack trace.

trace should be formatted in the same way as a Dart VM or browser stack trace. If it's formatted as a stack chain, this will return the equivalent of Chain.toTrace.

Implementation

factory Trace.parse(String trace) {
  try {
    if (trace.isEmpty) return new Trace(<Frame>[]);
    if (trace.contains(_v8Trace)) return new Trace.parseV8(trace);
    if (trace.contains("\tat ")) return new Trace.parseJSCore(trace);
    if (trace.contains(_firefoxSafariTrace)) {
      return new Trace.parseFirefox(trace);
    }
    if (trace.contains(chainGap)) return new Chain.parse(trace).toTrace();
    if (trace.contains(_friendlyTrace)) {
      return new Trace.parseFriendly(trace);
    }

    // Default to parsing the stack trace as a VM trace. This is also hit on
    // IE and Safari, where the stack trace is just an empty string (issue
    // 11257).
    return new Trace.parseVM(trace);
  } on FormatException catch (error) {
    throw new FormatException('${error.message}\nStack trace:\n$trace');
  }
}