printStackTrace method

void printStackTrace([
  1. bool useErrorPrint = false
])

Extension on RuntimeException to support pretty stack trace printing.

Usage:

try {
  throw RuntimeException('Oops!');
} catch (e) {
  if (e is RuntimeException) {
    e.printStackTrace();
  }
}

Implementation

void printStackTrace([bool useErrorPrint = false]) {
  if (useErrorPrint) {
    Error.safeToString(toString()).split('\n').forEach(print);
  } else {
    print(toString());
  }
}