Xref: utzoo comp.lang.c++:12467 comp.std.c++:776 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!think.com!linus!linus!maestro!fkuhl From: fkuhl@maestro.mitre.org (F. S. Kuhl) 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: <1991Mar26.124326.4996@linus.mitre.org> Date: 26 Mar 91 12:43:26 GMT References: <8862@chorus.fr> <1991Mar25.154302.4357@world.std.com> Sender: news@linus.mitre.org (News Service) Reply-To: fkuhl@maestro.mitre.org (F. S. Kuhl) Organization: The MITRE Corporation, McLean, Va Lines: 18 Nntp-Posting-Host: maestro.mitre.org In article <1991Mar25.154302.4357@world.std.com>, wmm@world.std.com (William M Miller) writes: |> |> 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 |> } Is it true that a constructor returns NULL if it fails? A quick look thru ARM failed to settle this point. -- Frederick Kuhl fkuhl@mitre.org Civil Systems Division The MITRE Corporation