home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / NeoPersist 3.0.8 folder / NeoIncludes / NeoFailure.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.6 KB  |  89 lines  |  [TEXT/MMCC]

  1. /************************************************************
  2.  *
  3.  *  Created: Friday, December 4, 1992 7:32:00 AM
  4.  *  NeoFailure.h
  5.  *  Definition of failure contructs
  6.  *
  7.  *  Copyright © Neologic Systems 1992-1993. All Rights Reserved.
  8.  *  All rights reserved
  9.  *
  10.  ***********************************************************/
  11. #pragma once
  12. #ifndef __NEOFAILURE__
  13. #define __NEOFAILURE__ 1          /* Include this file only once */
  14.  
  15. #include "NeoTypes.h"
  16.  
  17. #define qNeoFailures            1
  18.  
  19. #include <setjmp.h>
  20.  
  21. typedef struct FailInfo
  22. {
  23.     char            fPropagate;
  24.     struct FailInfo *next;
  25.     jmp_buf         regs;
  26. } FailInfo;
  27.  
  28. // Macros for handling failures
  29. extern short        gLastError;     /* last error code that caused a failure  */
  30. extern long         gLastMessage;   /* last message associated with a failure */
  31. void ArmHandler(FailInfo *aFailInfo);
  32. void FailMemError(void);
  33. void FailNIL(const void *aPtr);
  34. void FailOSErr(const OSErr aError);
  35. void Failure(const OSErr aError, const long aMsg);
  36. void RetryException(FailInfo *aFailInfo);
  37. void Success(void);
  38. void NoHandler(void);
  39. void SetFailInfo(const short aError, const long aMessage);
  40. long SpecifyMsg(const short aListID, const short aIndex);
  41.  
  42. #define NEOTRY                              \
  43.         { FailInfo __fi;                    \
  44.           ArmHandler(&__fi);                \
  45.           if (!setjmp(__fi.regs)) {
  46.         
  47. #define NEOCATCH                            \
  48.             Success(); }                    \
  49.         else {
  50.         
  51. #define NEOENDTRY                           \
  52.         if (__fi.fPropagate)                \
  53.         Failure(gLastError, gLastMessage);  \
  54.         }   }
  55.             
  56. #define NEORETRY                            \
  57.         RetryException(&__fi)
  58.         
  59. #define NO_PROPAGATE                        \
  60.         __fi.fPropagate = 0
  61.         
  62. #define NEOTRYTO                            \
  63.         { int __result;                     \
  64.           FailInfo __fi;                    \
  65.           ArmHandler(&__fi);                \
  66.           __result = setjmp(__fi.regs);        \
  67.           if (!__result) {
  68.         
  69. #define NEOCLEANUP                          \
  70.             Success(); }
  71.         
  72. #define NEOENDTRYTO                         \
  73.         if (__result && __fi.fPropagate)    \
  74.         Failure(gLastError, gLastMessage);  \
  75.         }
  76.  
  77. #define TRY                                    NEOTRY
  78. #define CATCH                                NEOCATCH
  79. #define ENDTRY                                NEOENDTRY
  80. #define RETRY                                NEORETRY
  81. #define TRYTO                                NEOTRYTO
  82. #define CLEANUP                                NEOCLEANUP
  83. #define ENDTRYTO                            NEOENDTRYTO
  84.  
  85.  
  86. #define NeoPropagateFailure(x)                __fi.fPropagate = (x)
  87. #define NeoFailErr()                        gLastError
  88. #endif
  89.