2 ms·
I don't agree that returning an Either is better than returning/throwing. It depends on what you do in the error case. If you try to recover, then Either is bet
by Strilanc 15y ago
I don't agree that returning an Either is better than returning/throwing. It depends on what you do in the error case. If you try to recover, then Either is better. If you fail fast, then throwing is better.
The main problem with checked exceptions, at least in Java, is the clumsiness of doing things right. Ideally every function would expose exceptions corresponding to useful error cases. Instead, because there's so much boilerplate involved in creating new exception types and wrapping exceptions as the proper type, programmers are more likely to swallow or blindly propagate.
I believe making checked exceptions signifcantly better is as easy as adding two features to Java:
- Easy wrapping. 'wraps Type1 as Type2' for try blocks and function signatures.
- Easy inline defining of new exceptions. 'throws forge ParityMismatch extends IllegalArgumentException'
- aidenn0 15y agoIf you read the comments, the author wrote a comment that basically says this. Exceptions should be used for fatal errors, not for recoverable errors.