To be fair, if tutorial is official, it could do a better job on educating about handling error conditions of the operation. Like it or not, but large amount of tutorial readers will do exactly that: copy and paste code without going into depths of what's going on there.