Created
March 21, 2021 06:10
-
-
Save devjaime/a3c3bea0316ccbf5c553dd2b91110b3d to your computer and use it in GitHub Desktop.
Cómo usar try, on, catch, rethrow,finally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<void> printWeather() async { | |
| try { | |
| final api = WeatherApiClient(); | |
| final weather = await api.getWeather('London'); | |
| print(weather); | |
| } on SocketException catch (_) { | |
| print('No se pudieron recuperar los datos. Comprueba tu conexión'); | |
| } on WeatherApiException catch (e) { | |
| print(e.message); | |
| } catch (e, st) { | |
| print('Error: $e\nStack trace: $st'); | |
| rethrow; | |
| } finally { | |
| print('Done'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment