|
|
|
|
|
by wvenable
3349 days ago
|
|
> The C++/Java/C# problem of exceptions being more expensive than you'd like for common error situations. Exceptions should not be used for common error situations! This is the prime mistake of Java which pretty much required exceptions when it should (and checked exceptions to boot). > .NET has sprouted alternatives like `bool tryParse(String, out int)` as a workaround I don't consider that a workaround. There is a deep semantic difference between TryParse and Parse. If you see TryParse then you know the data is expected to be invalid. If you see Parse than you know it's expected to be always valid. A good C# program should have very very few try/catch blocks (ideally just one). |
|
Sure, but I don't think that splitting every possibly-failing API call into throwing and non-throwing forms is the right way to express that difference, and a lot of the time it'll be a matter of context (meaning that the implementation can't magically do the right thing).
It's fairly easy to layer throwing behaviour on top of nonthrowing in a generic and efficient way (Rust's Option, Java's Optional etc), but the reverse is not true.
I must admit I'm losing track of what if anything we're in disagreement about, though...