runWithErrorHandler function
Implementation
void runWithErrorHandler(GlobalErrorHandler handler, void Function() block) {
// handle flutter framework errors
FlutterError.onError = handler.onFlutterError;
// handle uncaught dart errors (not supported on Web)
if (!kIsWeb) {
Isolate.current.addErrorListener(
// ignore: avoid_types_on_closure_parameters
RawReceivePort((List<dynamic> pair) async {
handler.onSerializedError(pair.first as String, (pair.last as String?)?.let(StackTrace.fromString));
}).sendPort,
);
}
// run app and handle uncaught failed futures
runZonedGuarded(block, handler.onOtherError);
}