jeromq
jeromq copied to clipboard
Should we avoid throwing unchecked exceptions?
#674 made me start to question why we throw unchecked exceptions.
It seems to me like we might want to only throw checked exceptions, because that way, the library user will not be surprised if we throw an exception, and the compiler will force them to handle the exceptions.
I'm biased, of course, in that I like checked exceptions; I know that not everyone agrees.
Thoughts?
I like checked exception too. But there is the problem of the API change. Adding throws everywhere will brake code. That's why I have written my ZMQCheckedException.raise(RuntimeException ex), see https://github.com/fbacchella/LogHub/blob/master/src/main/java/loghub/zmq/ZMQCheckedException.java, that might help.
I think we do have the option of bumping the major version to indicate significant breakage and making the change we want to make.
I'm not sure, in this case, how we could possibly make this change in a non-breaking way to give users time to adjust.
TBH, it might be best to just create a new API if the change is drastic and leave the old one as is but deprecate it. That's how Pieter used to go about things by accreting information.