Let's say in a Flutter app we want to catch any uncaught exceptions/errors at the top level, so we do this as per the docs:
main() {
// All uncaught errors thrown from synchronous code blocks will end up here:
FlutterError.onError = (FlutterErrorDetails details) {
MyLogger.instance.logUncaughtErrorSync(details);
};
// All uncaught errors thrown from async code blocks will end up here:
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
MyLogger.instance.logUncaughtErrorASync(error, stack);
return true;
};
runApp(const MyApp());
While the docs seems to imply that the distinction between the two is whether the error originated in Dart (and specifically "Flutter") code vs platform (Android/IOS) code, through my testing, the only difference I can tell between the two is whether the Object (error) was thrown from async vs sync Dart code.
For example, if in Dart code, (not platform code), we simply put:
_function() async {
throw('error');
}
and we call that function, it will bubble up through the "platform dispatcher" and is considered a "platform error," but seemingly only because it happened on a background thread?
The appears to actually be no mechanism allowing Exceptions thrown from Java or Swift code to trigger either of these onError functions.
There must be more to it than this though, so whats the point of having two separate mechanisms (with different inputs -- FlutterErrorDetails vs Object+StackTrace)... and what's the real difference?