home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / Moofwars 1.02 / Tim's Libraries / Error Macros.h < prev    next >
Encoding:
Text File  |  1998-08-10  |  1.2 KB  |  40 lines  |  [TEXT/CWIE]

  1. /*********************************************************************************
  2. ERROR HANDLING MACROS
  3. #
  4. These macros can be used to implement nice error handling within a function.
  5. Essentially, all errors jump to an error handler at the end of the function, which
  6. should cleanup  any leftovers and return the appropriate error result.
  7. #
  8. Note that the error handlers take a message string.  This should be a good
  9. indication of the actual error, and it will appear when debugging is turned on.
  10. #
  11. Note that any additional sanity checking code can be added to any function by using
  12. #
  13.     
  14.     #if qDebugging
  15.           // do additional sanity checking here.
  16.     #endif
  17. #
  18. For example, this could be used to check the internal validity of an object before
  19. taking an action.
  20.  
  21. *********************************************************************************/
  22. // App may want to override qDebugging
  23. #include "AppConditionals.h"
  24.  
  25. #pragma once
  26.  
  27. #ifndef qDebugging
  28.     #define qDebugging 0
  29. #endif
  30.  
  31. #if qDebugging
  32.     #define SIGNAL_ERROR(msg)        {DebugStr(msg); goto error;}
  33. #else
  34.     #define SIGNAL_ERROR(msg)        {goto error;}
  35. #endif
  36.  
  37. #define FAIL_NIL(y,msg)            if (y == NULL) SIGNAL_ERROR(msg)
  38. #define FAIL_OSERR(y,msg)        if (y != noErr) SIGNAL_ERROR(msg)
  39. #define FAIL_FALSE(y,msg)        if (!y) SIGNAL_ERROR(msg)
  40.