Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Failed constructors ( Was Re: Failed allocation in constructors? ) Keywords: exception handling Message-ID: <329@taumet.com> Date: 21 Jul 90 18:01:32 GMT References: <11061@alice.UUCP> Organization: Taumetric Corporation, San Diego Lines: 30 garry@alice.UUCP (garry hodgson) writes: >What I'd like to do is something like: > Connection *connection = new Connection( "kgbvax", PortNum ); > if ( connection ) > SendSecretDocuments( connection ); > else ComplainLoudly(); >Instead, what I do is: > Connection *connection = new Connection( "kgbvax", PortNum ); > if ( connection->status() == GoAhead ) > SendSecretDocuments( connection ); > else ComplainLoudly(); Sounds to me like a coding style issue. If you really object to coding if ( connection->status() == GoAhead ) you could define operator() or operator! as in the streams library, and code if ( (*connection)() ) // ok or if ( !*connection ) // fail In general, it would seem to be an advantage to detect the difference between out of memory and the constructor failing for some other reason. -- Steve Clamage, TauMetric Corp, steve@taumet.com