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. Advertising

  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. Advertising

  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. Advertising

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,079
    Ralf Hildebrandt
    Sep 8, 2003
  2. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,225
    Jürgen Exner
    Jul 31, 2003
  3. Jussi Mononen

    Math::Pari test fail on Compaq OSF1 5.1b

    Jussi Mononen, Jan 2, 2004, in forum: Perl
    Replies:
    0
    Views:
    677
    Jussi Mononen
    Jan 2, 2004
  4. Kai Wu
    Replies:
    6
    Views:
    744
    Kai Wu
    Oct 10, 2004
  5. Wenjie

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

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

Share This Page