On 2/24/07, Matthias Wessendorf <[EMAIL PROTECTED]> wrote:
Hi,

what do you guys think to change the method to return null, incase of
there is no dialog with the desired name ?


While you can find a lot of APIs that do this sort of thing, the
current design represents my biases on the topic lately:

* If you are looking up something that is "optional", and
 it's normal to sometimes expect that you might not find
 anything, return null.

* If you are looking up something that your application
 cannot do without, throw an exception.  The application
 can still catch the exception if it knows how to recover.

I've seen too many cases where the former approach was used, but the
application developer is faced with some difficult to diagnose NPE
later on, simply because they "assumed" the looked-up item would
always be there.  I'd rather throw the IAE directly, and tell the
developer exactly what's wrong -- also known as "fail fast" coding
:-).

Craig

-M

--
Matthias Wessendorf
http://tinyurl.com/fmywh

further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Reply via email to