Returning nil vs throwing an exception

This is a discussion on Returning nil vs throwing an exception within the Object forums in Theory and Concepts category; Hi! What's the recommended practice if a factory cannot return a proper object reference? Throwing an exception or return a null pointer/reference? Or it this a matter of taste simply? -- Best regards, Pi (Ralf Pichocki)....

Go Back   Application Development Forum > Theory and Concepts > Object

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-11-2008, 03:15 AM
Ralf Pichocki
Guest
 
Default Returning nil vs throwing an exception

Hi!

What's the recommended practice if a factory cannot return a proper object
reference?
Throwing an exception or return a null pointer/reference? Or it this a
matter of taste simply?

--
Best regards, Pi (Ralf Pichocki).


Reply With Quote
  #2  
Old 08-11-2008, 09:19 AM
Douglas C. Schmidt
Guest
 
Default Re: Returning nil vs throwing an exception

Hi Ralf,

> What's the recommended practice if a factory cannot return a proper object
> reference?
> Throwing an exception or return a null pointer/reference? Or it this a
> matter of taste simply?


It's a matter of taste, but I recommend throwing an exception since
it's cleaner, particularly if you're using an OO language.

Thanks,

Doug
--
Dr. Douglas C. Schmidt Professor and Associate Chair
Electrical Engineering and Computer Science TEL: (615) 343-8197
Vanderbilt University WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203 NET: d.schmidt@vanderbilt.edu
Reply With Quote
  #3  
Old 08-11-2008, 10:11 AM
Jonathan Biggar
Guest
 
Default Re: Returning nil vs throwing an exception

Douglas C. Schmidt wrote:
> Hi Ralf,
>
>> What's the recommended practice if a factory cannot return a proper object
>> reference?
>> Throwing an exception or return a null pointer/reference? Or it this a
>> matter of taste simply?

>
> It's a matter of taste, but I recommend throwing an exception since
> it's cleaner, particularly if you're using an OO language.


It also can return more information to the client, like a reason string.

--
Jon Biggar
Floorboard Software
jon@floorboard.com
jon@biggar.org
Reply With Quote
  #4  
Old 08-11-2008, 11:41 AM
Ralf Pichocki
Guest
 
Default Re: Returning nil vs throwing an exception

Hi, Doug, hi, Jonathan!

Thanks for the both of you - that's what I expected. Wilco.

Best regards, Pi (Ralf Pichocki).


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:05 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.