3 ms·
panic/recover is good and necessary to have, Rust also has this. Swift’s fatalError is not recoverable which is very frustrating. I don’t like go much - langua
by jitl 2y ago
panic/recover is good and necessary to have, Rust also has this. Swift’s fatalError is not recoverable which is very frustrating.
I don’t like go much - languages that can have nil pointer errors can take a hike, but what I like even less than a nil pointer error while handling a request, is for my whole process to die unrecoverably because someone forgot to check a nil in an infrequently called API. Or when comparing something that’s not allowed to be compared. Like the language would be better if these mistakes were impossible to make, but as long as we have a language with a plethora of garden variety syntax can panic like `a.b` or `a == b` we should be able to mitigate that risk at runtime.
- bb88 2y agoIn golang, `panic()` and `return err` are two different ways of unwinding the stack. 80% of my error handling in go is `return nil, err`. But there's no reason syntactic sugar couldn't be applied for something like `when err { return nil, err} { err := doSomething() }`