how to fail initialize

Discussion in 'Ruby' started by Jim, Feb 16, 2007.

  1. Jim

    Jim Guest

    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/.
     
    Jim, Feb 16, 2007
    #1
    1. Advertisements

  2. Jim

    Guest

    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
     
    , Feb 16, 2007
    #2
    1. Advertisements

  3. Jim

    Jim Bob Guest

    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/.
     
    Jim Bob, Feb 16, 2007
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    4
    Views:
    2,437
    Ralf Hildebrandt
    Sep 8, 2003
  2. Jussi Mononen

    Math::Pari test fail on Compaq OSF1 5.1b

    Jussi Mononen, Jan 2, 2004, in forum: Perl
    Replies:
    0
    Views:
    872
    Jussi Mononen
    Jan 2, 2004
  3. Charles Shannon Hendrix

    REGEX: capturing on optional groups which fail

    Charles Shannon Hendrix, Jun 14, 2004, in forum: Perl
    Replies:
    0
    Views:
    637
    Charles Shannon Hendrix
    Jun 14, 2004
  4. Replies:
    0
    Views:
    684
  5. Fred
    Replies:
    0
    Views:
    685
  6. Sobhan Vezzu
    Replies:
    0
    Views:
    2,621
    Sobhan Vezzu
    Dec 19, 2003
  7. Kai Wu
    Replies:
    6
    Views:
    1,045
    Kai Wu
    Oct 10, 2004
  8. Wenjie

    if (f() != FAIL) or if (FAIL != f())?

    Wenjie, Jul 28, 2003, in forum: C Programming
    Replies:
    3
    Views:
    641
    E. Robert Tisdale
    Jul 31, 2003
Loading...