| ▲ | mort96 2 hours ago | ||||||||||||||||
What do you do if you wanna return the file (or an object containing the file) in the happy path but close it in the error path? | |||||||||||||||||
| ▲ | cogman10 2 hours ago | parent [-] | ||||||||||||||||
You'd write it like this
That said, I think this is a bad practice (IMO). Generally speaking I think the opening and closing of a resource should happen at the same scope.Making it non-local is a recipe for an accident. *EDIT* I've made a mistake while writing this, but I'll leave it up there because it demonstrates my point. The file is left open if a bad thing happens. | |||||||||||||||||
| |||||||||||||||||