Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by anonymoushn

1 day ago

defer { close all the files in the collection }

?

2 comments

anonymoushn

Reply

gwd  1 day ago

OK, 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  1 day ago

    You 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.

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities