From 55e10a66305939341cc41cfdbe6be0dfe653f3c6 Mon Sep 17 00:00:00 2001 From: Michael Thomsen Date: Thu, 2 Mar 2017 16:15:52 +0100 Subject: [PATCH] Add exception handling (#8528) --- examples/platform_services/lib/main.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/platform_services/lib/main.dart b/examples/platform_services/lib/main.dart index aeaf795969..300604a81b 100644 --- a/examples/platform_services/lib/main.dart +++ b/examples/platform_services/lib/main.dart @@ -17,10 +17,16 @@ class _PlatformServicesState extends State { String _location = 'Unknown location.'; Future _getLocation() async { - List result = await platform.invokeMethod('getLocation', 'network'); + String location; + try { + List 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; }); }