[openbeos] Re: Asserts?

  • From: "shatty" <shatty@xxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 06 Oct 2002 02:30:07 -0700

-----Original Message-----
From: Scott Mansfield <thephantom@xxxxxxx>
Date: Sat, 5 Oct 2002 22:49:40 -0700


Now, suppose I blithely ignore InitCheck() and use one if this suspect 
class' accessors?  I might get back good data, I might not.  It's a 
crap shoot.


What I am asking is if it would be, within the OBOS realm, proper and 
prudent to assert() from an accessor if the class is not properly 
initialized (i.e.: InitCheck() would return B_ERROR)?


IHMO, If your accessor returns a status_t you should usually return
B_NO_INIT.  The Be API is inconsistent on this matter but generally
you should also return B_NO_INIT from InitCheck() if the initialization
failed or is
incomplete.  This is especially the case if the situation is recoverable.
For example, there are a number of classes where you can create an 
empty instance with a default null constructor and then later call a
SetTo method to complete the initialization.

Taking an example from the media kit: BMediaFile::GetFileFormatInfo

It's not completely unreasonable for a programmer to write the following:

BMediaFile file(someEntryRef);
if (file.GetFileFormatInfo(formatInfo) != B_OK) {
  .. some other stuff..

Using the Be Book as a standard, said programmer would have considerable
support for being upset if GetFileFormatInfo simply asserted that the file
pointer was valid.


Other related posts: