Skip to content

Instantly share code, notes, and snippets.

@MelvinRB27
Created October 5, 2023 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelvinRB27/233dccf0e90f0388d7904c4c25491c3a to your computer and use it in GitHub Desktop.
Save MelvinRB27/233dccf0e90f0388d7904c4c25491c3a to your computer and use it in GitHub Desktop.
try, catch, on y finally

try, catch, on y finally

Created with <3 with dartpad.dev.

void main() async {
try {
final value = await httpGet("melvin");
print(value);
} on Exception catch (err) {
print('Hubo un error de Exception: $err');
} catch (err) {
print('OOPS! Error: $err');
} finally {
print('Se completó el try-catch');
}
}
Future<String> httpGet(String url) async {
await Future.delayed(Duration(seconds: 1));
//return 'Respuesta http';
//throw 'Hubo un error';
throw Exception('Hubo un error');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment