Add exception handling (#8528)
diff --git a/examples/platform_services/lib/main.dart b/examples/platform_services/lib/main.dart index aeaf795..300604a 100644 --- a/examples/platform_services/lib/main.dart +++ b/examples/platform_services/lib/main.dart
@@ -17,10 +17,16 @@ String _location = 'Unknown location.'; Future<Null> _getLocation() async { - List<double> result = await platform.invokeMethod('getLocation', 'network'); + String location; + try { + List<double> result = await platform.invokeMethod('getLocation', 'network'); + location = 'Latitude ${result[0]}, Longitude ${result[1]}.'; + } on PlatformException catch (e) { + location = "Failed to get location: '${e.message}'."; + } setState(() { - _location = 'Latitude ${result[0]}, Longitude ${result[1]}.'; + _location = location; }); }