Article View: chorus.os.chorus
Article #4Re: How can I report an error when constructor parameters are wrong.
From: William M Miller
Date: Mon, 25 Mar 1991 15:43
Date: Mon, 25 Mar 1991 15:43
17 lines
1269 bytes
1269 bytes
ev@chorus.fr (Eric Valette) writes:
> * I would like to have opinions about the best way to check constructor
> * parameters validity and report error to caller: I think that something
> * is missing in the way you can report error to user using Cfront 2.0
This is true and is one of the main motivations behind the addition of
exceptions to the language. In the meantime, about the best that can be
done is to add a member function that can be interrogated after allocation
to ensure that the constructor succeeded; something like
if (!(p = new some_class) || p->ctor_failed()) {
delete p; // allowed even if p == 0
// handle cleanup
}
-- William M. Miller, Glockenspiel, Ltd.
wmm@world.std.com
Technical Details
Message-ID:
<1991Mar25.154302.4357@world.std.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!world!wmmReferences:
<8862@chorus.fr>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!world!wmm From: wmm@world.std.com (William M Miller) Newsgroups: chorus.os.chorus,comp.lang.c++,comp.std.c++ Subject: Re: How can I report an error when constructor parameters are wrong. Message-ID: <1991Mar25.154302.4357@world.std.com> Date: 25 Mar 91 15:43:02 GMT References: <8862@chorus.fr> Organization: The World Public Access UNIX, Brookline, MA Lines: 17