I want to handle the exception from the 'onData' function(the first positional parameter), but the onError is not fired when the exception is thrown. I just got an 'Unhandled Exception' warning.
Am I misunderstanding the 'onError' on usage? When will it be fired?
The codes:
final Logger log = Logger('test logger');
client.getUrl(Uri.parse(url)).then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
try {
response.listen((d) {
throw Exception("TEST EXCEPTION");
}, onDone: () {
log.finer("onDone");
}, onError: (e, stack) {
log.warning("onError");
}, cancelOnError: true);
} catch (e, stack) {
log.warning("listen");
}
}).catchError((e, stack) {
log.warning("future");
});