Skip to content

Instantly share code, notes, and snippets.

@miquelbeltran
Created November 22, 2019 16:35
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 miquelbeltran/3c05eea33346f28794f28d7665e5e77c to your computer and use it in GitHub Desktop.
Save miquelbeltran/3c05eea33346f28794f28d7665e5e77c to your computer and use it in GitHub Desktop.
Did you add the onError to the listen() method?
import 'dart:async';
StreamSubscription streamWithError(Stream<String> stream) {
return stream.listen((_) {} /* finish this method */);
}
StreamSubscription streamWithError(Stream<String> stream) {
return stream.listen((_) {}, onError: (error) {});
}
void main() async {
var hadError = false;
// catch unhandled onError
runZoned(() {
// ignore: close_sinks
final streamController = StreamController<String>(sync: true);
// ignore: cancel_subscriptions
final subscription = streamWithError(streamController.stream);
if (subscription == null) {
_result(
false, ['Something went wrong! The stream subscription is missing.']);
hadError = true;
return;
}
streamController.addError("ERROR!");
}, onError: (e, stackTrace) {
_result(false,
['Something went wrong! Looks like the error was not processed.']);
hadError = true;
});
if (!hadError) {
_result(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment