PATHMac OS 8 Developer Documentation > Mutlimedia and Graphics > ColorSync Manager >

Managing Color With ColorSync


Poor Man's Exception Handling

Listing 3-3 shows a macro definition that is used in several subsequent code listings. In this macro, if assertion evaluates to false , execution continues at the location exception . Otherwise, execution continues at the next statement following the macro.

Listing 3-3 Poor man's exception handling macro

// Equivalent to if ((assertion) == false) goto exception;
#define require(assertion, exception)   \
    do {                                \
        if (assertion) ;                \
        else { goto exception; }        \
    } while (false)

You can find examples of how to use this macro in Listing 3-4 , Listing 3-5 and others. While this style of "poor man's exception handling" may not appeal to all developers, it does offer these advantages:


© 1988-1999 Apple Computer, Inc. — (Last Updated 20 Jan 99)