No one “deserves” free time. If you don’t want to work 70 hours a week and want to watch Netflix instead, go for it, but don’t bitch to me
Some people suffer and think "I had to go through this so everyone else should too."
The starting example is how I'd do it in C:
```
void f(const char* p) // unsafe, naive use
{
FILE \*f = fopen(p, "r"); // acquire
// use f
fclose(f); // release
}```
Wouldn't the simpler solution be ensuring your function doesn't exit before release? All that c++ destroyer stuff appears somewhat unnecessary and as the author points out, creates even more problems.
> if err != nil return err
That is, a `throw` statement in Swift simply returns an `Error` value to the caller via a special return path instead of the normal result.
More explicitly, a Swift function declared as:
func f() throws -> T {
}
Could be read as func f() -> (T|any Error) {
}
More here: https://github.com/swiftlang/swift/blob/main/docs/ErrorHandl...https://github.com/swiftlang/swift-evolution/blob/main/propo...
I say limited because the compiler doesn't (yet, as of 6.2) perform typed throw inference for closures (a closure that throws is inferred to throw `any Error`). I have personally found this sufficiently limiting that I've given up using typed throws in the few places I want to, for now.