-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eid exceptions do not extend their Java counterparts, maybe they should? #11
Comments
I think that API of any library should be as most obvious as possible for programmer. When I first saw EidIllegalStateException usage in code, I was pretty sure that it is kind of IllegalStateException. When I jump into implementation of Eid*Exception I was surprised that it is not extending one of common java exceptions. So in my opinion EId exceptions should extend their Java counterparts. |
I thinking the same now. Closing on behalf of #13 |
Today I've run on some issue with this changed approach. Consider the following code: try {
return runSomeRiskyOperation();
} catch (RuntimeException ex) {
Eid eid;
if (ex instanceof EidContainer) {
eid = ((EidContainer) ex).getEid();
} else {
eid = new Eid("20181109:174712");
}
throw new EidIllegalStateException(eid, ex);
} On line Using current approach I can write this code as (much more tidy in my opinion): try {
return runSomeRiskyOperation();
} catch (EidRuntimeException ex) {
throw ex;
} catch (RuntimeException ex) {
throw new EidIllegalStateException(new Eid("20181109:174712"), ex);
} Your thoughts? @adamfabijanczyk |
Inheriting directly from Java's specific run time exceptions gives us nothing good. Users shouldn't catch specific version of run time exception, ever. Inheriting from specific Java's run time exceptions gives us only one advantage, that is it will be more obvious in that way (for ex.: Ingeriting from specific Java's run time exceptions came with a cost. That cost was described in my post above. Addtionally, it's handy to catch all Eid exceptions in error handler. That's a real use case. Taking all that into account, I'm inclined to leave the current behavior in place. Please, convince me I'm wrong. |
Actually Eid exceptions do not extend their Java counterparts.
It's good idea to rethink, is that the right way.
Given for
ex instanceof EidIllegalStateException
, it's basically to chose what's more beneficial:or
We can't have both. There is also
EidContainer
interface, thus it can be like:The text was updated successfully, but these errors were encountered: