Skip to content

Instantly share code, notes, and snippets.

@devjaime
Created March 21, 2021 06:10
Show Gist options
  • Select an option

  • Save devjaime/a3c3bea0316ccbf5c553dd2b91110b3d to your computer and use it in GitHub Desktop.

Select an option

Save devjaime/a3c3bea0316ccbf5c553dd2b91110b3d to your computer and use it in GitHub Desktop.
Cómo usar try, on, catch, rethrow,finally.
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