Actually what i'm doing in my code base is duplicating already existing java checked exceptions like MalformedURLException.class
by keeping the same exception name while inheriting from RuntimeException.class . Sincerly,i did not find a better way.
I found that really bad,because i've now nearly 8 exceptions duplicated just because, in my case, i can't recover from theses types of exceptions and i don't want to throw them from each level until they reach the higher level as it would make code maintainability a nightmare.
Frankly, i think that oracle/sun should have thought about this case of re-usability and make the type of exceptions flexible and chosen at the moment of throwing, something like the following instead of relying upon exception's parent :
throwChecked new MalformedURLException();
IMO RuntimeException.class and Exception.class both should be uncheck exception and it is up to the developer to choose how it'll be thrown.
- so my question, did i miss something in my case and analysis ?
- and does exist a better approach without duplicating?
Best regards !
Edit
Note also by duplicating theses exceptions, i found myself obligated to cover all the branches of my classes hence cover all the created exceptions too if i want to have a good coverage.