java api design - NULL or Exception
Posted
by srini.venigalla
on Stack Overflow
See other posts from Stack Overflow
or by srini.venigalla
Published on 2010-02-11T16:27:21Z
Indexed on
2010/06/14
6:22 UTC
Read the original article
Hit count: 245
Is it better to return a null value or throw an exception from an API method?
Returning a null requires ugly null checks all over, and cause a major quality problem if the return is not checked.
Throwing an exception forces the user to code for the faulty condition, but since Java exceptions bubble up and force the caller code to handle them, in general, using custom exceptions may be a bad idea (specifically in java).
Any sound and practical advice?
© Stack Overflow or respective owner