home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!bnr.co.uk!uknet!mcsun!sunic!sics.se!eua.ericsson.se!euas62c36!euamts
- From: euamts@eua.ericsson.se (Mats Henricson)
- Newsgroups: comp.lang.c++
- Subject: Re: Memory allocation failures and good de
- Message-ID: <1992Dec21.094614.21432@eua.ericsson.se>
- Date: 21 Dec 92 09:46:14 GMT
- References: <1992Dec20.123719.4017@ucc.su.OZ.AU>
- Sender: news@eua.ericsson.se
- Reply-To: euamts@eua.ericsson.se
- Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
- Lines: 31
- Nntp-Posting-Host: euas62c36.eua.ericsson.se
-
- In article 4017@ucc.su.OZ.AU, maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- #In article <720@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:
- #>In article <1992Dec03.135428.33868@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
- #>>
- #>>My advice is add a member function isOk(), and ensure that this function
- #>>only returns TRUE if all memory allocation, (or other resource use,
- #>>eg opening files) was performed ok. Then you can do:
- #>>
- #>> SomeObject* object = new SomeObject;
- #>> if (object->isOk() == FALSE)
- #>> {
- #>> // handle error.
- #>> }
- #>>
- #>
- #>Unfortunately there is more to it than that:
- #>
- #>You cannot call pObj->isOk() until you first check to see that
- #>you got any sort of object back from new.
- #>
- # You can if you make isOK a static member.
- # Setting 'new_handler' seems a good idea in many programs though.
-
- An isOK() function might want to acces some private data before deciding
- if the object is OK or not, but a static function can only access static
- data. I agree, though, on the setting of new_handler.
-
- Mats Henricson
- Ellemtel
- Stockholm
- Sweden
-