void dumpErrorToConsole(FlutterErrorDetails details, { bool forceReport: false })

Prints the given exception details to the console.

The first time this is called, it dumps a very verbose message to the console using debugPrint.

Subsequent calls only dump the first line of the exception, unless forceReport is set to true (in which case it dumps the verbose message).

Call resetErrorCount to cause this method to go back to acting as if it had not been called before (so the next message is verbose again).

The default behavior for the onError handler is to call this function.

Source

static void dumpErrorToConsole(FlutterErrorDetails details, { bool forceReport: false }) {
  assert(details != null);
  assert(details.exception != null);
  bool reportError = details.silent != true; // could be null
  assert(() {
    // In checked mode, we ignore the "silent" flag.
    reportError = true;
    return true;
  });
  if (!reportError && !forceReport)
    return;
  if (_errorCount == 0 || forceReport) {
    final String header = '\u2550\u2550\u2561 EXCEPTION CAUGHT BY ${details.library} \u255E'.toUpperCase();
    final String footer = '\u2550' * _kWrapWidth;
    debugPrint('$header${"\u2550" * (footer.length - header.length)}');
    final String verb = 'thrown${ details.context != null ? " ${details.context}" : ""}';
    if (details.exception is NullThrownError) {
      debugPrint('The null value was $verb.', wrapWidth: _kWrapWidth);
    } else if (details.exception is num) {
      debugPrint('The number ${details.exception} was $verb.', wrapWidth: _kWrapWidth);
    } else {
      String errorName;
      if (details.exception is AssertionError) {
        errorName = 'assertion';
      } else if (details.exception is String) {
        errorName = 'message';
      } else if (details.exception is Error || details.exception is Exception) {
        errorName = '${details.exception.runtimeType}';
      } else {
        errorName = '${details.exception.runtimeType} object';
      }
      debugPrint('The following $errorName was $verb:', wrapWidth: _kWrapWidth);
      debugPrint('${details.exception}', wrapWidth: _kWrapWidth);
    }
    Iterable<String> stackLines = (details.stack != null) ? details.stack.toString().trimRight().split('\n') : null;
    if ((details.exception is AssertionError) && (details.exception is! FlutterError)) {
      bool ourFault = true;
      if (stackLines != null) {
        List<String> stackList = stackLines.take(2).toList();
        if (stackList.length >= 2) {
          final RegExp throwPattern = new RegExp(r'^#0 +_AssertionError._throwNew \(dart:.+\)$');
          final RegExp assertPattern = new RegExp(r'^#1 +[^(]+ \((.+?):([0-9]+)(?::[0-9]+)?\)$');
          if (throwPattern.hasMatch(stackList[0])) {
            final Match assertMatch = assertPattern.firstMatch(stackList[1]);
            if (assertMatch != null) {
              assert(assertMatch.groupCount == 2);
              final RegExp ourLibraryPattern = new RegExp(r'^package:flutter/');
              ourFault = ourLibraryPattern.hasMatch(assertMatch.group(1));
            }
          }
        }
      }
      if (ourFault) {
        debugPrint('\nEither the assertion indicates an error in the framework itself, or we should '
                   'provide substantially more information in this error message to help you determine '
                   'and fix the underlying cause.', wrapWidth: _kWrapWidth);
        debugPrint('In either case, please report this assertion by filing a bug on GitHub:', wrapWidth: _kWrapWidth);
        debugPrint('  https://github.com/flutter/flutter/issues/new');
      }
    }
    if (details.stack != null) {
      debugPrint('\nWhen the exception was thrown, this was the stack:', wrapWidth: _kWrapWidth);
      if (details.stackFilter != null) {
        stackLines = details.stackFilter(stackLines);
      } else {
        stackLines = defaultStackFilter(stackLines);
      }
      for (String line in stackLines)
        debugPrint(line, wrapWidth: _kWrapWidth);
    }
    if (details.informationCollector != null) {
      StringBuffer information = new StringBuffer();
      details.informationCollector(information);
      debugPrint('\n$information', wrapWidth: _kWrapWidth);
    }
    debugPrint(footer);
  } else {
    debugPrint('Another exception was thrown: ${details.exception.toString().split("\n")[0]}');
  }
  _errorCount += 1;
}