printZoneError function

void printZoneError(
  1. Object error,
  2. StackTrace stackTrace, {
  3. String? title,
  4. String? message,
  5. bool printErrorToStderr = true,
})

Prints an error and stackTrace.

See printToZoneStderr.

Implementation

void printZoneError(
  Object error,
  StackTrace stackTrace, {
  String? title,
  String? message,
  bool printErrorToStderr = true,
}) {
  var s = StringBuffer();

  s.write(
    '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n',
  );

  if (title != null) {
    s.write('$title\n\n');
  }

  var errorMsg = error.toString().trim();
  s.write('$errorMsg\n\n');

  s.write('StackTrace:\n$stackTrace\n');

  if (message != null && message.isNotEmpty) {
    s.write(
      '------------------------------------------------------------------------------\n\n',
    );
    s.write('$message\n');
  }

  s.write(
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n',
  );

  if (printErrorToStderr) {
    printToZoneStderr(s);
  } else {
    print(s);
  }
}