Menu

#40 RuntimeExceptions should be chained if caught

open
5
2012-12-07
2009-10-19
No

see AbstractEntityRegistrationManager:

} catch (RuntimeException e) {
throw new EntitiesRegistrationException(e.getMessage());

should be:

} catch (RuntimeException e) {
throw new EntitiesRegistrationException(e.getMessage(), e);

But even better: don't catch it all! RuntimeExceptions should not be caught if you can't perfectly handle them. Just let them bubble up the stack.
That code is doing nothing more then obscuring the real exception.
This could be added though:

if (entity == null) {
throw new IllegalArgumentException("The entity (" + entity + ") must not be null.");
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB