6 ms·
defer { close all the files in the collection } ?
by anonymoushn 1y ago
defer { close all the files in the collection }
?
- gwd 1y agoOK, what happens now if you have an error opening one of those files, return an error from inside the for loop, and forget to close the files you'd already opened?
- tczMUFlmoNk 1y agoYou put the files in the collection as you open them, and you register the defer before opening any of them. It works fine. Defer should be lexically scoped.