[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sv: I'm back



Bjarke Hammersholt Roune wrote:

>>* I'm now doing a ppWarning ("Invalid Arguments"); when an API function
>>in PFile is called with an invalid parameter and ppWarning ("Out of
>>Memory"); when "new" fails. We should standardize on such messages so
>>that the user can just grep over the debug output and get meaningful
>>results. Ideas for more standard messages?
>>
>I propose an IMHO slightly more convinient way of doing things, that will
>actually enforce the standards and make them easily changeable at a later
>time:
>
>#define PP_CHECK_ARG(EXP) \
>    if (!(EXP)) \
>        ppWarning("Invalid argument");
>
>To see how this is a good idea, consider this code:
>
>void ppSomeFunction(ppBlah* p1, ppBlah* p2)
>{
>#ifdef PP_DEBUG // (can't remember the correct symbol)
>    if (p1 == 0)
>        ppWarning("Invalid argument");
>    if (p2 == 0)
>        ppWarning("Invalid argument");
>#endif
>
>    // ...
>}
>
>and then compare with this:
>
>void ppSomeFunction(ppBlah* p1, ppBlah* p2)
>{
>    PP_CHECK_ARG(p1 != 0);
>    PP_CHECK_ARG(p2 != 0);
>
>    // ...
>}

Bad. You forget that the function should fail on an invalid arg, i.e.
either return an error code or throw an exception. It's not possible to
make a generic convenient macro for this.

>I also think it would be a good idea to define this macro:
>
>#define PP_ASSERT_ARG(EXP) \
>    if (!(EXP)) \
>    { \
>        ppWarning("Invalid argument"); \
>        ppAssert(false); \
>    }

That would print:
WARNING: In function "foo" at foofile: 123 : Invalid Argument
ERROR (I): In function "foo" at foofile: 124 : Assertion false failed

somehow weird ;)
Calling ppInternalError () instead of ppWarning () and ppAssert () would be
better.
But in any case this is only useful for internal code (that can't be called
directly by the user), and for that a simple ppAssert (Arg == valid); is
fine.

>#define PP_WARN_NEW_FAIL \
>    ppWarning("Out of memory");
>
>#define PP_WARN_INVALID_ARG \
>    ppWarning("Invalid argument"); // update the above macroes where this
>message is used

These are useful, right.

>Other errors messages could be "Unknown internal PenguinPlay error",
>"Unknown internal PenguinSound error" etc.

I'd only use the generic PPlay message here - after all the file name and
function in which it originated are printed as well. 
>"Invalid path", 
>"Non-existant file specified in path", 
>"Invalid file-system specifier", 
>"Non-existant directory specified in path", 
>"Object could not be constructed" (ie, exception thrown from
>constructor), 
>"Could not initialise component", 
>"Memory corrupted or bug". 

Uh, don't know about the last one...

>PP_WARN_INTERNAL_ERR
>PP_WARN_INTERNAL_ERR_PSOUND
>PP_WARN_INVALID_PATH
>PP_WARN_INVALID_FILE
>PP_WARN_INVALID_DIR
>PP_WARN_INVALID_FS
>PP_WARN_NO_CONSTRUCT
>PP_WARN_NO_COMPONENT_INIT
>PP_WARN_BAD_MEM
>
>This will make it possible to get these kinds of warningmessages 100%
>standardised, and will make it very easy to change them later.

Agreed.


	Christian
--

Drive A: not responding...Formatting C: instead