Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to fail initialize

Reply
Thread Tools

how to fail initialize

 
 
Jim
Guest
Posts: n/a
 
      02-16-2007
I would like to know the correct way to fail the creating of an object.
I would return a NULL in c/c++ but returning a nil does not to seem to
work correctly i.e.

if(obj) then do stuff

OR

if(obj != nil) then do stuff

New to Ruby if you couldn't guess.

Jim.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      02-16-2007
On Sat, 17 Feb 2007, Jim wrote:

> I would like to know the correct way to fail the creating of an object.
> I would return a NULL in c/c++ but returning a nil does not to seem to
> work correctly i.e.
>
> if(obj) then do stuff
>
> OR
>
> if(obj != nil) then do stuff
>
> New to Ruby if you couldn't guess.
>


def initialize
raise
end

the code is easier to work with if it either returns valid results, or raises
an exception - i removes the burden of testing return values in the client
code.

kind regards.

-a
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama

 
Reply With Quote
 
 
 
 
Jim Bob
Guest
Posts: n/a
 
      02-16-2007
Thanks for quick response, I decided to do error testing before creating
object thus removing the problem, I find exception handling messy.

Thanks,
Jim.


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How do you initialize signals in VHDL? Madhu VHDL 7 05-28-2008 06:43 PM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
Fail to initialize struct from fstream Kai Wu C++ 6 10-10-2004 02:01 AM
if (f() != FAIL) or if (FAIL != f())? Wenjie C Programming 3 07-31-2003 09:54 PM



Advertisments