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

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