OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [AddErrInfo.3] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1989-1993 The Regents of the University of California.
3
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: AddErrInfo.3,v 1.1.1.1 2002-01-16 10:25:23 markom Exp $
9
'\"
10
.so man.macros
11
.TH Tcl_AddErrorInfo 3 7.5 Tcl "Tcl Library Procedures"
12
.BS
13
.SH NAME
14
Tcl_AddObjErrorInfo, Tcl_AddErrorInfo, Tcl_SetErrorCode, Tcl_PosixError \- record information about errors
15
.SH SYNOPSIS
16
.nf
17
\fB#include \fR
18
.sp
19
\fBTcl_AddObjErrorInfo\fR(\fIinterp, message, length\fR)
20
.sp
21
\fBTcl_AddErrorInfo\fR(\fIinterp, message\fR)
22
.sp
23
\fBTcl_SetObjErrorCode\fR(\fIinterp, errorObjPtr\fR)
24
.sp
25
\fBTcl_SetErrorCode\fR(\fIinterp, element, element, ... \fB(char *) NULL\fR)
26
.sp
27
char *
28
\fBTcl_PosixError\fR(\fIinterp\fR)
29
.SH ARGUMENTS
30
.AS Tcl_Interp *message
31
.AP Tcl_Interp *interp in
32
Interpreter in which to record information.
33
.AP char *message in
34
For \fBTcl_AddObjErrorInfo\fR,
35
this points to the first byte of an array of bytes
36
containing a string to record in the \fBerrorInfo\fR variable.
37
This byte array may contain embedded null bytes
38
unless \fIlength\fR is negative.
39
For \fBTcl_AddErrorInfo\fR,
40
this is a conventional C string to record in the \fBerrorInfo\fR variable.
41
.AP int length in
42
The number of bytes to copy from \fImessage\fR when
43
setting the \fBerrorInfo\fR variable.
44
If negative, all bytes up to the first null byte are used.
45
.AP Tcl_Obj *errorObjPtr in
46
This variable \fBerrorCode\fR will be set to this value.
47
.AP char *element in
48
String to record as one element of \fBerrorCode\fR variable.
49
Last \fIelement\fR argument must be NULL.
50
.BE
51
 
52
.SH DESCRIPTION
53
.PP
54
These procedures are used to manipulate two Tcl global variables
55
that hold information about errors.
56
The variable \fBerrorInfo\fR holds a stack trace of the
57
operations that were in progress when an error occurred,
58
and is intended to be human-readable.
59
The variable \fBerrorCode\fR holds a list of items that
60
are intended to be machine-readable.
61
The first item in \fBerrorCode\fR identifies the class of
62
error that occurred
63
(e.g. POSIX means an error occurred in a POSIX system call)
64
and additional elements in \fBerrorCode\fR hold additional pieces
65
of information that depend on the class.
66
See the Tcl overview manual entry for details on the various
67
formats for \fBerrorCode\fR.
68
.PP
69
The \fBerrorInfo\fR variable is gradually built up as an
70
error unwinds through the nested operations.
71
Each time an error code is returned to \fBTcl_EvalObj\fR
72
(or \fBTcl_Eval\fR, which calls \fBTcl_EvalObj\fR)
73
it calls the procedure \fBTcl_AddObjErrorInfo\fR to add
74
additional text to \fBerrorInfo\fR describing the
75
command that was being executed when the error occurred.
76
By the time the error has been passed all the way back
77
to the application, it will contain a complete trace
78
of the activity in progress when the error occurred.
79
.PP
80
It is sometimes useful to add additional information to
81
\fBerrorInfo\fR beyond what can be supplied automatically
82
by \fBTcl_EvalObj\fR.
83
\fBTcl_AddObjErrorInfo\fR may be used for this purpose:
84
its \fImessage\fR and \fIlength\fR arguments describe an additional
85
string to be appended to \fBerrorInfo\fR.
86
For example, the \fBsource\fR command calls \fBTcl_AddObjErrorInfo\fR
87
to record the name of the file being processed and the
88
line number on which the error occurred;
89
for Tcl procedures, the procedure name and line number
90
within the procedure are recorded, and so on.
91
The best time to call \fBTcl_AddObjErrorInfo\fR is just after
92
\fBTcl_EvalObj\fR has returned \fBTCL_ERROR\fR.
93
In calling \fBTcl_AddObjErrorInfo\fR, you may find it useful to
94
use the \fBerrorLine\fR field of the interpreter (see the
95
\fBTcl_Interp\fR manual entry for details).
96
.PP
97
\fBTcl_AddErrorInfo\fR resembles \fBTcl_AddObjErrorInfo\fR
98
but differs in initializing \fBerrorInfo\fR from the string
99
value of the interpreter's result
100
if the error is just starting to be logged.
101
It does not use the result as a Tcl object
102
so any embedded null characters in the result
103
will cause information to be lost.
104
It also takes a conventional C string in \fImessage\fR
105
instead of \fBTcl_AddObjErrorInfo\fR's counted string.
106
.PP
107
The procedure \fBTcl_SetObjErrorCode\fR is used to set the
108
\fBerrorCode\fR variable. \fIerrorObjPtr\fR contains a list object
109
built up by the caller. \fBerrorCode\fR is set to this
110
value. \fBTcl_SetObjErrorCode\fR is typically invoked just
111
before returning an error in an object command. If an error is
112
returned without calling \fBTcl_SetObjErrorCode\fR or
113
\fBTcl_SetErrorCode\fR the Tcl interpreter automatically sets
114
\fBerrorCode\fR to \fBNONE\fR.
115
.PP
116
The procedure \fBTcl_SetErrorCode\fR is also used to set the
117
\fBerrorCode\fR variable. However, it takes one or more strings to
118
record instead of an object. Otherwise, it is similar to
119
\fBTcl_SetObjErrorCode\fR in behavior.
120
.PP
121
\fBTcl_PosixError\fR
122
sets the \fBerrorCode\fR variable after an error in a POSIX kernel call.
123
It reads the value of the \fBerrno\fR C variable and calls
124
\fBTcl_SetErrorCode\fR to set \fBerrorCode\fR in the \fBPOSIX\fR format.
125
The caller must previously have called \fBTcl_SetErrno\fR to set
126
\fBerrno\fR; this is necessary on some platforms (e.g. Windows) where Tcl
127
is linked into an application as a shared library, or when the error
128
occurs in a dynamically loaded extension. See the manual entry for
129
\fBTcl_SetErrno\fR for more information.
130
.PP
131
\fBTcl_PosixError\fR returns a human-readable diagnostic message
132
for the error
133
(this is the same value that will appear as the third element
134
in \fBerrorCode\fR).
135
It may be convenient to include this string as part of the
136
error message returned to the application in
137
the interpreter's result.
138
.PP
139
It is important to call the procedures described here rather than
140
setting \fBerrorInfo\fR or \fBerrorCode\fR directly with
141
\fBTcl_ObjSetVar2\fR.
142
The reason for this is that the Tcl interpreter keeps information
143
about whether these procedures have been called.
144
For example, the first time \fBTcl_AddObjErrorInfo\fR is called
145
for an error, it clears the existing value of \fBerrorInfo\fR
146
and adds the error message in the interpreter's result to the variable
147
before appending \fImessage\fR;
148
in subsequent calls, it just appends the new \fImessage\fR.
149
When \fBTcl_SetErrorCode\fR is called, it sets a flag indicating
150
that \fBerrorCode\fR has been set;
151
this allows the Tcl interpreter to set \fBerrorCode\fR to \fBNONE\fR
152
if it receives an error return
153
when \fBTcl_SetErrorCode\fR hasn't been called.
154
.PP
155
If the procedure \fBTcl_ResetResult\fR is called,
156
it clears all of the state associated with
157
\fBerrorInfo\fR and \fBerrorCode\fR
158
(but it doesn't actually modify the variables).
159
If an error had occurred, this will clear the error state to
160
make it appear as if no error had occurred after all.
161
 
162
.SH "SEE ALSO"
163
Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_Interp, Tcl_ResetResult, Tcl_SetErrno
164
 
165
.SH KEYWORDS
166
error, object, object result, stack, trace, variable

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.