A journal of Programming, Technology and Management notes
Tuesday, April 19, 2016
return null vs. throw exception
Its not wise to return null when any business logic is incorrect
its best to throw an exception when there's a validation error or a required field missing.
This way you can propagate the error up the stack
Example:
if(imageTicket == null) {
throw new ImageTicketNotFoundException("Could not find a image ticket for the id provided");
}
No comments:
Post a Comment