printStackTrace method

void printStackTrace([
  1. StackTrace? stacktrace,
  2. bool useErrorPrint = false
])

Prints the exception and optional StackTrace if available.

Usage:

try {
  throw FormatException('Invalid format');
} catch (e) {
  (e as Exception).printStackTrace();
}

Implementation

void printStackTrace([StackTrace? stacktrace, bool useErrorPrint = false]) {
  if (useErrorPrint) {
    stderr.write(this);
  } else {
    print(this);
  }

  if (stacktrace != null) {
    if (useErrorPrint) {
      stderr.write(stacktrace);
    } else {
      print(stacktrace);
    }
  }
}