[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
>#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");
>    // ...
>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
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

>#define PP_WARN_NEW_FAIL \
>    ppWarning("Out of memory");
>    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
>"Could not initialise component", 
>"Memory corrupted or bug". 

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

>This will make it possible to get these kinds of warningmessages 100%
>standardised, and will make it very easy to change them later.



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