home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!noc.near.net!hri.com!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!rpi!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Newsgroups: comp.lang.c++
- Subject: Re: Memory allocation failures and good design question
- Message-ID: <1992Dec20.123719.4017@ucc.su.OZ.AU>
- Date: 20 Dec 92 12:37:19 GMT
- References: <1992Dec2.182524.10716@porthos.cc.bellcore.com> <1992Dec03.135428.33868@rs6000.bham.ac.uk> <720@ulogic.UUCP>
- Sender: news@ucc.su.OZ.AU
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- Lines: 28
- Nntp-Posting-Host: extro.ucc.su.oz.au
-
- 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.
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-