reportExceptionNoticed method Null safety

  1. @override
void reportExceptionNoticed(
  1. FlutterErrorDetails exception
)
override

Called when the framework catches an exception, even if that exception is being handled by takeException.

This is called when there is no pending exception; if multiple exceptions are thrown and takeException isn't used, then subsequent exceptions are logged to the console regardless (and the test will fail).

Implementation

@override
void reportExceptionNoticed(FlutterErrorDetails exception) {
  final DebugPrintCallback testPrint = debugPrint;
  debugPrint = debugPrintOverride;
  debugPrint('(The following exception is now available via WidgetTester.takeException:)');
  FlutterError.dumpErrorToConsole(exception, forceReport: true);
  debugPrint(
    '(If WidgetTester.takeException is called, the above exception will be ignored. '
    'If it is not, then the above exception will be dumped when another exception is '
    'caught by the framework or when the test ends, whichever happens first, and then '
    'the test will fail due to having not caught or expected the exception.)'
  );
  debugPrint = testPrint;
}