errorbase.pp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. (******************************************************************************
  2. *
  3. * Copyright (c) 1994-2000 Palm, Inc. or its subsidiaries.
  4. * All rights reserved.
  5. *
  6. * File: ErrorBase.h
  7. *
  8. * Release: Palm OS SDK 4.0 (63220)
  9. *
  10. * Description:
  11. * Include file for Error Management
  12. *
  13. * History:
  14. * 10/25/94 RM Created by Ron Marianetti
  15. * 10/09/98 Bob Fill in all macros, fix defns w/ do{}while(0)
  16. * 08/05/99 kwk Added menuErrorClass from Gavin's Menu.c
  17. * 05/10/00 kwk Added intlErrorClass.
  18. * 08/24/00 SCL Added hwrErrorClass.
  19. *
  20. *-----------------------------------------------------------------------
  21. * Exception Handling
  22. *
  23. * This unit implements an exception handling mechanism that is similar
  24. * to "real" C++ Exceptions. Our Exceptions are untyped, and there
  25. * must be one and only one Catch block for each Try block.
  26. *
  27. * Try/Catch Syntax:
  28. *
  29. * ErrTry {
  30. * // Do something which may fail.
  31. * // Call ErrThrow() to signal failure and force jump
  32. * // to the following Catch block.
  33. * }
  34. *
  35. * ErrCatch(inErr) {
  36. * // Recover or cleanup after a failure in the above Try block.
  37. * // "inErr" is an ExceptionCode identifying the reason
  38. * // for the failure.
  39. *
  40. * // You may call Throw() if you want to jump out to
  41. * // the next Catch block.
  42. *
  43. * // The code in this Catch block does not execute if
  44. * // the above Try block completes without a Throw.
  45. *
  46. * } ErrEndCatch
  47. *
  48. * You must structure your code exactly as above. You can't have a
  49. * ErrTry { } without a ErrCatch { } ErrEndCatch, or vice versa.
  50. *
  51. *
  52. * ErrThrow
  53. *
  54. * To signal failure, call ErrThrow() from within a Try block. The
  55. * Throw can occur anywhere in the Try block, even within functions
  56. * called from the Try block. A ErrThrow() will jump execution to the
  57. * start of the nearest Catch block, even across function calls.
  58. * Destructors for stack-based objects which go out of scope as
  59. * a result of the ErrThrow() are called.
  60. *
  61. * You can call ErrThrow() from within a Catch block to "rethrow"
  62. * the exception to the next nearest Catch block.
  63. *
  64. *
  65. * Exception Codes
  66. *
  67. * An ExceptionCode is a 32-bit number. You will normally use
  68. * Pilot error codes, which are 16-bit numbers. This allows
  69. * plently of room for defining codes for your own kinds of errors.
  70. *
  71. *
  72. * Limitations
  73. *
  74. * Try/Catch and Throw are based on setjmp/longjmp. At the
  75. * beginning of a Try block, setjmp saves the machine registers.
  76. * Throw calls longjmp, which restores the registers and jumps
  77. * to the beginning of the Catch block. Therefore, any changes
  78. * in the Try block to variables stored in registers will not
  79. * be retained when entering the Catch block.
  80. *
  81. * The solution is to declare variables that you want to use
  82. * in both the Try and Catch blocks as "volatile". For example:
  83. *
  84. * volatile long x = 1; // Declare volatile local variable
  85. * ErrTry {
  86. * x = 100; // Set local variable in Try
  87. * ErrThrow(-1);
  88. * }
  89. *
  90. * ErrCatch(inErr) {
  91. * if (x > 1) { // Use local variable in Catch
  92. * SysBeep(1);
  93. * }
  94. * } ErrEndCatch
  95. *
  96. *****************************************************************************)
  97. unit errorbase;
  98. interface
  99. uses palmos, coretraps;
  100. // Max message length supported by ErrCustomAlert
  101. const
  102. errMaxMsgLength = 511;
  103. (************************************************************
  104. * Error Classes for each manager
  105. *************************************************************)
  106. errNone = $0000; // No error
  107. memErrorClass = $0100; // Memory Manager
  108. dmErrorClass = $0200; // Data Manager
  109. serErrorClass = $0300; // Serial Manager
  110. slkErrorClass = $0400; // Serial Link Manager
  111. sysErrorClass = $0500; // System Manager
  112. fplErrorClass = $0600; // Floating Point Library
  113. flpErrorClass = $0680; // New Floating Point Library
  114. evtErrorClass = $0700; // System Event Manager
  115. sndErrorClass = $0800; // Sound Manager
  116. almErrorClass = $0900; // Alarm Manager
  117. timErrorClass = $0A00; // Time Manager
  118. penErrorClass = $0B00; // Pen Manager
  119. ftrErrorClass = $0C00; // Feature Manager
  120. cmpErrorClass = $0D00; // Connection Manager (HotSync)
  121. dlkErrorClass = $0E00; // Desktop Link Manager
  122. padErrorClass = $0F00; // PAD Manager
  123. grfErrorClass = $1000; // Graffiti Manager
  124. mdmErrorClass = $1100; // Modem Manager
  125. netErrorClass = $1200; // Net Library
  126. htalErrorClass = $1300; // HTAL Library
  127. inetErrorClass = $1400; // INet Library
  128. exgErrorClass = $1500; // Exg Manager
  129. fileErrorClass = $1600; // File Stream Manager
  130. rfutErrorClass = $1700; // RFUT Library
  131. txtErrorClass = $1800; // Text Manager
  132. tsmErrorClass = $1900; // Text Services Library
  133. webErrorClass = $1A00; // Web Library
  134. secErrorClass = $1B00; // Security Library
  135. emuErrorClass = $1C00; // Emulator Control Manager
  136. flshErrorClass = $1D00; // Flash Manager
  137. pwrErrorClass = $1E00; // Power Manager
  138. cncErrorClass = $1F00; // Connection Manager (Serial Communication)
  139. actvErrorClass = $2000; // Activation application
  140. radioErrorClass = $2100; // Radio Manager (Library)
  141. dispErrorClass = $2200; // Display Driver Errors.
  142. bltErrorClass = $2300; // Blitter Driver Errors.
  143. winErrorClass = $2400; // Window manager.
  144. omErrorClass = $2500; // Overlay Manager
  145. menuErrorClass = $2600; // Menu Manager
  146. lz77ErrorClass = $2700; // Lz77 Library
  147. smsErrorClass = $2800; // Sms Library
  148. expErrorClass = $2900; // Expansion Manager and Slot Driver Library
  149. vfsErrorClass = $2A00; // Virtual Filesystem Manager and Filesystem library
  150. lmErrorClass = $2B00; // Locale Manager
  151. intlErrorClass = $2C00; // International Manager
  152. pdiErrorClass = $2D00; // PDI Library
  153. attnErrorClass = $2E00; // Attention Manager
  154. telErrorClass = $2F00; // Telephony Manager
  155. hwrErrorClass = $3000; // Hardware Manager (HAL)
  156. blthErrorClass = $3100; // Bluetooth Library Error Class
  157. udaErrorClass = $3200; // UDA Manager Error Class
  158. oemErrorClass = $7000; // OEM/Licensee errors (0x7000-0x7EFF shared among ALL partners)
  159. errInfoClass = $7F00; // special class shows information w/o error code
  160. appErrorClass = $8000; // Application-defined errors
  161. (********************************************************************
  162. * Try / Catch / Throw support
  163. *
  164. * ---------------------------------------------------------------------
  165. * Exception Handler structure
  166. *
  167. * An ErrExceptionType object is created for each ErrTry & ErrCatch block.
  168. * At any point in the program, there is a linked list of
  169. * ErrExceptionType objects. GErrFirstException points to the
  170. * most recently entered block. A ErrExceptionType blocks stores
  171. * information about the state of the machine (register values)
  172. * at the start of the Try block
  173. ********************************************************************)
  174. type
  175. ErrJumpBuf = array [0..12-1] of ^Integer; // D3-D7,PC,A2-A7
  176. // Structure used to store Try state.
  177. type
  178. ErrExceptionPtr = ^ErrExceptionType;
  179. ErrExceptionType = record
  180. nextP: ErrExceptionPtr; // next exception type
  181. state: ErrJumpBuf; // setjmp/longjmp storage
  182. err: Int32; // Error code
  183. end;
  184. // Try & Catch macros
  185. (*
  186. #define ErrTry
  187. {
  188. ErrExceptionType _TryObject;
  189. _TryObject.err = 0;
  190. _TryObject.nextP = (ErrExceptionPtr)*ErrExceptionList();
  191. *ErrExceptionList() = (MemPtr)&_TryObject;
  192. if (ErrSetJump(_TryObject.state) == 0) {
  193. *)
  194. // NOTE: All variables referenced in and after the ErrCatch must
  195. // be declared volatile. Here's how for variables and pointers:
  196. // volatile UInt16 oldMode;
  197. // ShlDBHdrTablePtr volatile hdrTabP = nil;
  198. // If you have many local variables after the ErrCatch you may
  199. // opt to put the ErrTry and ErrCatch in a separate enclosing function.
  200. (*
  201. #define ErrCatch(theErr)
  202. *ErrExceptionList() = (MemPtr)_TryObject.nextP;
  203. }
  204. else {
  205. Int32 theErr = _TryObject.err;
  206. *ErrExceptionList() = (MemPtr)_TryObject.nextP;
  207. *)
  208. (*
  209. #define ErrEndCatch
  210. }
  211. }
  212. *)
  213. (********************************************************************
  214. * Error Manager Routines
  215. ********************************************************************)
  216. //function ErrSetJump(buf: ErrJumpBuf): Int16; syscall sysTrapErrSetJump;
  217. //procedure ErrLongJump(buf: ErrJumpBuf; result: Int16); syscall sysTrapErrLongJump;
  218. function ErrExceptionList: MemPtrPtr; syscall sysTrapErrExceptionList;
  219. procedure ErrThrow(err_: Int32); syscall sysTrapErrThrow;
  220. procedure ErrDisplayFileLineMsg(const filename: PChar; lineNo: UInt16; const msg: PChar); syscall sysTrapErrDisplayFileLineMsg;
  221. //---------------------------------------------------------------------
  222. // 2/25/98 - New routine for PalmOS >3.0 to display a UI alert for
  223. // run-time errors. This is most likely to be used by network applications
  224. // that are likely to encounter run-time errors like can't find the server,
  225. // network down, etc. etc.
  226. //
  227. // This routine will lookup the text associated with 'errCode' and display
  228. // it in an alert. If errMsgP is not NULL, then that text will be used
  229. // instead of the associated 'errCode' text. If 'preMsgP' or 'postMsgP'
  230. // is not null, then that text will be pre-pended or post-pended
  231. // respectively.
  232. //
  233. // Apps that don't use the extra parameters may want to just use the
  234. // macro below 'ErrAlert'
  235. //---------------------------------------------------------------------
  236. function ErrAlertCustom(errCode: Err; errMsgP, preMsgP, postMsgP: PChar): UInt16; syscall sysTrapErrAlertCustom;
  237. function ErrAlert(err: Err): UInt16;
  238. implementation
  239. function ErrAlert(err: Err): UInt16;
  240. begin
  241. ErrAlert := ErrAlertCustom(err, nil, nil, nil);
  242. end;
  243. end.