onError method

  1. @override
void onError(
  1. FlutterErrorDetails details
)
inherited

Supply an 'error handler' routine to fire when an error occurs. Override if you like to customize error handling.

Implementation

// details.exception, details.stack
/// Override if you like to customize error handling.
@override
void onError(FlutterErrorDetails details) {
  // Don't call this routine within itself.
  if (inErrorRoutine) {
    return;
  }
  // In case there's an error in this routine
  inErrorRoutine = true;

  try {
    // If handler not explicitly passed as a parameter
    var callOriginal = _errorHandler?.errorHandler == null;

    if (!callOriginal) {
      _errorHandler?.errorHandler?.call(details);
    }

    // Any 'on' Error handler
    onErrorHandler(details);

    // It would appear it was not overwritten
    callOriginal = callOriginal && !_errorHandlerOverridden;

    // No 'in-line' version
    callOriginal = callOriginal && inErrorHandler == null;

    if (callOriginal) {
      _errorHandler?.oldOnError?.call(details);
    } else {
      // 'inline function' error handler, takes last precedence.
      inErrorHandler?.call(details);
    }
  } catch (e, stack) {
    recordException(e, stack);
  }
  // Always test if there was an error in the error handler
  // Include it in the error reporting as well.
  if (hasError) {
    _onErrorInHandler();
  }

  // If in testing, after the supplied handler, call its Error handler
  if (_errorHandler?.errorHandler != null &&
      WidgetsBinding.instance is! WidgetsFlutterBinding) {
    _errorHandler?.oldOnError?.call(details);
  }

  inErrorRoutine = false;
}