▲ | quotemstr a day ago | ||||||||||||||||
Checked exceptions are more trouble than they're worth. That doesn't make exceptions in general bad. | |||||||||||||||||
▲ | mathw a day ago | parent | next [-] | ||||||||||||||||
Not having checked exceptions is a huge problem, because then you never know when something might throw and what it might through, and in the .NET world the documentation on that is pretty awful and absolutely incomplete. But then over in Java world, your checked exception paradise (which it of course isn't because the syntax and toolkit for managing the things is so clunky) is easily broken by the number of unchecked exceptions which could be thrown from anything at any time and break your code in unexpected and exciting ways, so not only do you have to deal with that system you also don't get any assurance that it's even worth doing. But this doesn't actually mean checked exceptions are a bad idea, it means that Java didn't implement them very well (largely because it also has unchecked exceptions, and NullPointerException is unchecked because otherwise the burden of handling it would be hideous, but that comes down to reference types being nullable by default, which is a whole other barrel of pain they didn't have to do, and oh look, Go did the same thing wooo). | |||||||||||||||||
| |||||||||||||||||
▲ | Cthulhu_ a day ago | parent | prev | next [-] | ||||||||||||||||
What does make exceptions bad in my opinion (and shared by Go developers?) is a few things: 1. Exceptions are expensive (at least in Java / C#), as they generate a stack trace every time. Which is fine for actually exceptional situations, the equivalent of `panic()` in Go, but: 2. Exceptions are thrown for situations that are not exceptional, e.g. files that don't exist, database rows that don't exist, etc. Those are simple business logic cases. The workaround is defensive coding, check if the file exists first, check if the row exists? that kind of thing. 3. The inconsistency between checked and unchecked exceptions. 4. Distance - but this is developer / implementation specific - between calling a function that can throw an error and handling it. But #2 is the big one I think. Go's error handling is one solution, but if it's about correct code, then more functional languages that use the Either pattern or whatever it's called formally are even better. Go's approach is the more / most pragmatic of the options. | |||||||||||||||||
| |||||||||||||||||
▲ | OtomotO a day ago | parent | prev [-] | ||||||||||||||||
As said, I don't like the wrapping of about everything with try/catch Sure, you can only do it way up the stack, but that's not enough quite often. If you can only do it all the way up, I find it ergonomic. Maybe I should experiment more with catch unwind in Rust. |