Created
May 21, 2023 01:14
-
-
Save eseidel/f4c93eb9f9e24d43079cbc859a867894 to your computer and use it in GitHub Desktop.
confusing exception handling with futures
This file contains 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
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