onError method
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
@mustCallSuper
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 {
// Don't log the error again
_errorHandler?.logError = false;
// App's Error handler
_errorHandler?.flutteryExceptionHandler?.call(details);
// 'inline function' error handler, takes last precedence.
// Catch any errors below
inErrorHandler?.call(details);
// If App's Error handler was never defined
final callOriginal = _errorHandler?.flutteryExceptionHandler == null;
if (callOriginal) {
_errorHandler?.oldOnError?.call(details);
}
// This is a public function. ALWAYS catch an error or exception
} catch (e, stack) {
// Record the error
recordException(e, stack);
}
// In case there's errors in the two error handlers!!
Object? e;
StackTrace? stack;
// Always test if there was an error in the error handler
// Include it in the error reporting as well.
if (recHasError) {
//
stack = recStackTrace;
e = recordException(); // Record and clear
// Call the original error routine if debugging and not testing
if (v.kDebugMode && (WidgetsBinding.instance is WidgetsFlutterBinding)) {
try {
_errorHandler?.oldOnError?.call(details);
} catch (e, stack) {
// Record the error
recordException(e, stack);
}
}
}
// Always test if there was an error in the error handler
// Include it in the error reporting as well.
if (recHasError) {
//
InformationCollector? collector;
assert(() {
collector = () => <DiagnosticsNode>[
DiagnosticsProperty<FlutterErrorDetails>(
'FlutterErrorDetails',
details,
style: DiagnosticsTreeStyle.errorProperty,
),
];
return true;
}());
/// Report the error in an isolate or in a run zone.
_errorHandler?.reportError(
e,
stack: stack,
message: 'Error in onError()',
library: 'app_statex.dart',
informationCollector: collector,
);
}
// If in testing, after the supplied handler, call its Error handler
// An `Error` is a failure that the programmer should have avoided.
if (WidgetsBinding.instance is! WidgetsFlutterBinding) {
if (details.exception is TestFailure || details.exception is Error) {
// Allow an error to be ignored. Once!
if (ignoreErrorInTesting) {
_ignoreErrorInTesting = false;
} else {
_errorHandler?.oldOnError?.call(details);
}
}
}
_inErrorRoutine = false;
}