3 ms·
Can you turn an unchecked exception into a checked exception with a rule in your linter? Or would it just be too painful to catch UnsupportedOperationException
by dmurray 6y ago
Can you turn an unchecked exception into a checked exception with a rule in your linter? Or would it just be too painful to catch UnsupportedOperationException everywhere if you did that?
- mumblemumble 6y agoYou could, but I'd argue it's a dodgy thing to do. In general, the idea behind RuntimeException is that they're not checked because they're preventable errors that you should be able to avoid having in the first place, and it's therefore unwise to try to recover from them because they indicate that you've got a bug and the application may be in an untrustworthy state. Granted, that idea itself gets a bit dodgy. In the case of Collection<T>, for example, an isReadOnly method was not supplied, so we haven't really been given any good way to tell ahead of time if a particular collection instance supports mutation.
- dllthomas 6y agoAnd even then, the linter will only help if it's your code generating the exception.