My app gets images from Firebase storage. In the event that there exist no image I want to be able to handle the error. But I can't seem to get it working.
I have tried surrounding with try catch.
I have tried this
Future<dynamic> getImage(int index){
return FirebaseStorage.instance.ref().child(widget.snap[index].data['英文品名']+".jpg").getDownloadURL().catchError((onError){
print(onError);
});
}
and this
Future<dynamic> getImage(int index){
var imageStream;
try {
imageStream = FirebaseStorage.instance.ref().child(widget.snap[index].data['英文品名']+".jpg").getDownloadURL();
} catch (e) {
print(e);
}
return imageStream;
}
but I always get unhandled exception error and my app crashes.
E/StorageException(11819): StorageException has occurred.
E/StorageException(11819): Object does not exist at location.
E/StorageException(11819): Code: -13010 HttpResult: 404
E/StorageException(11819): StorageException has occurred.
E/StorageException(11819): Object does not exist at location.
E/StorageException(11819): Code: -13010 HttpResult: 404
E/StorageException(11819): { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
E/StorageException(11819): java.io.IOException: { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
How to handle this exception? Image of exception in VS Code