Skip to content

Instantly share code, notes, and snippets.

@eseidel
Created May 21, 2023 01:14
Show Gist options
  • Save eseidel/f4c93eb9f9e24d43079cbc859a867894 to your computer and use it in GitHub Desktop.
Save eseidel/f4c93eb9f9e24d43079cbc859a867894 to your computer and use it in GitHub Desktop.
confusing exception handling with futures
class ApiException implements Exception {
ApiException();
}
Future<void> inner() async {
throw ApiException();
}
Future<void> _middle() async {
try {
return inner();
} on ApiException catch (e) {
print('inner: $e');
}
}
Future<void> outer() async {
try {
await _middle();
} on ApiException catch (e) {
print('outer: $e');
}
}
void main() async {
await outer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment