home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18256 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.6 KB

  1. 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
  2. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Memory allocation failures and good design question
  5. Message-ID: <1992Dec20.123719.4017@ucc.su.OZ.AU>
  6. Date: 20 Dec 92 12:37:19 GMT
  7. References: <1992Dec2.182524.10716@porthos.cc.bellcore.com> <1992Dec03.135428.33868@rs6000.bham.ac.uk> <720@ulogic.UUCP>
  8. Sender: news@ucc.su.OZ.AU
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. Lines: 28
  11. Nntp-Posting-Host: extro.ucc.su.oz.au
  12.  
  13. In article <720@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:
  14. >In article <1992Dec03.135428.33868@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
  15. >>
  16. >>My advice is add a member function isOk(), and ensure that this function
  17. >>only returns TRUE if all memory allocation, (or other resource use,
  18. >>eg opening files) was performed ok. Then you can do:
  19. >>
  20. >>  SomeObject* object = new SomeObject;
  21. >>  if (object->isOk() == FALSE)
  22. >>  {
  23. >>    // handle error.
  24. >>  }
  25. >>
  26. >
  27. >Unfortunately there is more to it than that:
  28. >
  29. >You cannot call pObj->isOk() until you first check to see that
  30. >you got any sort of object back from new.
  31. >
  32.     You can if you make isOK a static member.
  33.     Setting 'new_handler' seems a good idea in many programs though.
  34.  
  35.  
  36. -- 
  37. ;----------------------------------------------------------------------
  38.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  39.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  40. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  41.