Last active
May 8, 2021 14:01
-
-
Save timnew/4bf9caaca179b50000b8abed1707a7d4 to your computer and use it in GitHub Desktop.
Try catch seems not working in async generator
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
Stream<String> test1(Future<String> future) async* { | |
try { | |
yield "a"; | |
yield await future; | |
yield "b"; | |
} catch (ex) { | |
yield ex.toString(); | |
} | |
yield "c"; | |
} | |
Stream<String> test2(Future<String> future) async* { | |
yield "a"; | |
yield await future.catchError((ex) => ex.toString()); | |
yield "c"; | |
} | |
Stream<String> test3(void Function() action) async* { | |
try{ | |
action(); | |
}catch (ex) { | |
yield ex.toString(); | |
} | |
} | |
Stream<String> test4() async* { | |
try { | |
yield "a"; | |
yield await Future.error("error"); | |
yield "b"; | |
} catch (ex) { | |
yield ex.toString(); | |
} | |
yield "c"; | |
} | |
Stream<String> test5() async* { | |
yield "a"; | |
yield await Future<String>.error("error").catchError((ex) => ex.toString()); | |
yield "c"; | |
} | |
Stream<String> test6() async* { | |
try{ | |
throw "error"; | |
}catch (ex) { | |
yield ex.toString(); | |
} | |
} | |
Future<void> printStream(Stream stream) async => print(await stream.toList()); | |
void main() async { | |
await printStream(test1(Future.error("error"))); | |
await printStream(test2(Future.error("error"))); | |
await printStream(test3(()=> throw "error")); | |
await printStream(test4()); | |
await printStream(test5()); | |
await printStream(test6()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment