jeromq icon indicating copy to clipboard operation
jeromq copied to clipboard

Should we avoid throwing unchecked exceptions?

Open daveyarwood opened this issue 6 years ago • 3 comments

#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?

daveyarwood avatar Feb 23 '19 14:02 daveyarwood

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.

fbacchella avatar Feb 23 '19 16:02 fbacchella

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.

daveyarwood avatar Feb 23 '19 16:02 daveyarwood

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.

trevorbernard avatar Feb 23 '19 18:02 trevorbernard