home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / AddErrInfo.3 next >
Text File  |  1993-04-16  |  6KB  |  144 lines

  1. '\"
  2. '\" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/AddErrInfo.3,v 1.15 93/04/08 13:54:29 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_AddErrorInfo tclc
  25. .BS
  26. .SH NAME
  27. Tcl_AddErrorInfo, Tcl_SetErrorCode, Tcl_PosixError \- record information about errors
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. \fBTcl_AddErrorInfo\fR(\fIinterp, message\fR)
  33. .sp
  34. \fBTcl_SetErrorCode\fR(\fIinterp, element, element, ...\fB (char *) NULL\fR)
  35. .sp
  36. char *
  37. \fBTcl_PosixError\fR(\fIinterp\fR)
  38. .SH ARGUMENTS
  39. .AS Tcl_Interp *message
  40. .AP Tcl_Interp *interp in
  41. Interpreter in which to record information.
  42. .AP char *message in
  43. Identifying string to record in \fBerrorInfo\fR variable.
  44. .AP char *element in
  45. String to record as one element of \fBerrorCode\fR variable.
  46. Last \fIelement\fR argument must be NULL.
  47. .BE
  48.  
  49. .SH DESCRIPTION
  50. .PP
  51. These procedures are used to manipulate two global variables
  52. that hold information about errors.
  53. The variable \fBerrorInfo\fR holds a stack trace of the
  54. operations that were in progress when an error occurred, and
  55. is intended to be human-readable.
  56. The variable \fBerrorCode\fR holds a list of items that
  57. are intended to be machine-readable.
  58. The first item in \fBerrorCode\fR identifies the class of
  59. .VS
  60. error that occurred (e.g. POSIX means an error occurred in
  61. .VE
  62. a POSIX system call) and additional elements in \fBerrorCode\fR
  63. hold additional pieces of information that depend on the class.
  64. See the Tcl overview manual entry for details on the various
  65. formats for \fBerrorCode\fR.
  66. .PP
  67. The \fBerrorInfo\fR variable is gradually built up as an
  68. error unwinds through the nested operations.
  69. Each time an error code is returned to \fBTcl_Eval\fR
  70. it calls the procedure \fBTcl_AddErrorInfo\fR to add
  71. additional text to \fBerrorInfo\fR describing the
  72. command that was being executed when the error occurred.
  73. By the time the error has been passed all the way back
  74. to the application, it will contain a complete trace
  75. of the activity in progress when the error occurred.
  76. .PP
  77. It is sometimes useful to add additional information to
  78. \fBerrorInfo\fR beyond what can be supplied automatically
  79. by \fBTcl_Eval\fR.
  80. \fBTcl_AddErrorInfo\fR may be used for this purpose:
  81. its \fImessage\fR argument contains an additional
  82. string to be appended to \fBerrorInfo\fR.
  83. For example, the \fBsource\fR command calls \fBTcl_AddErrorInfo\fR
  84. to record the name of the file being processed and the
  85. line number on which the error occurred;  for Tcl procedures, the
  86. procedure name and line number within the procedure are recorded,
  87. and so on.
  88. The best time to call \fBTcl_AddErrorInfo\fR is just after
  89. \fBTcl_Eval\fR has returned \fBTCL_ERROR\fR.
  90. In calling \fBTcl_AddErrorInfo\fR, you may find it useful to
  91. use the \fBerrorLine\fR field of the interpreter (see the
  92. \fBTcl_Interp\fR manual entry for details).
  93. .PP
  94. The procedure \fBTcl_SetErrorCode\fR is used to set the
  95. \fBerrorCode\fR variable.
  96. Its \fIelement\fR arguments give one or more strings to record
  97. in \fBerrorCode\fR:  each \fIelement\fR will become one item
  98. of a properly-formed Tcl list stored in \fBerrorCode\fR.
  99. \fBTcl_SetErrorCode\fR is typically invoked just before returning
  100. an error.
  101. If an error is returned without calling \fBTcl_SetErrorCode\fR
  102. then the Tcl interpreter automatically sets \fBerrorCode\fR
  103. to \fBNONE\fR.
  104. .PP
  105. \fBTcl_PosixError\fR
  106. .VS
  107. sets the \fBerrorCode\fR variable after an error in a POSIX kernel call.
  108. It reads the value of the \fBerrno\fR C variable and calls
  109. \fBTcl_SetErrorCode\fR to set \fBerrorCode\fR in the
  110. \fBPOSIX\fR format.
  111. In addition, \fBTcl_PosixError\fR returns a human-readable
  112. .VE
  113. diagnostic message for the error (this is the same value that
  114. will appear as the third element in \fBerrorCode\fR).
  115. It may be convenient to include this string as part of the
  116. error message returned to the application in \fIinterp->result\fR.
  117. .PP
  118. It is important to call the procedures described here rather than
  119. setting \fBerrorInfo\fR or \fBerrorCode\fR directly with
  120. \fBTcl_SetVar\fR.
  121. The reason for this is that the Tcl interpreter keeps information
  122. about whether these procedures have been called.
  123. For example, the first time \fBTcl_AppendResult\fR is called
  124. for an error, it clears the existing value of \fBerrorInfo\fR
  125. and adds the error message in \fIinterp->result\fR to the variable
  126. before appending \fImessage\fR;  in subsequent calls, it just
  127. appends the new \fImessage\fR.
  128. When \fBTcl_SetErrorCode\fR is called, it sets a flag indicating
  129. that \fBerrorCode\fR has been set;  this allows the Tcl interpreter
  130. to set \fBerrorCode\fR to \fBNONE\fB if it receives an error return
  131. when \fBTcl_SetErrorCode\fR hasn't been called.
  132. .PP
  133. If the procedure \fBTcl_ResetResult\fR is called, it clears all
  134. of the state associated with \fBerrorInfo\fR and \fBerrorCode\fR
  135. (but it doesn't actually modify the variables).
  136. If an error had occurred, this will clear the error state to
  137. make it appear as if no error had occurred after all.
  138.  
  139. .SH "SEE ALSO"
  140. Tcl_ResetResult, Tcl_Interp
  141.  
  142. .SH KEYWORDS
  143. error, stack, trace, variable
  144.