1 |
578 |
markom |
'\"
|
2 |
|
|
'\" Copyright (c) 1990 The Regents of the University of California.
|
3 |
|
|
'\" Copyright (c) 1994-1996 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: CrtErrHdlr.3,v 1.1.1.1 2002-01-16 10:25:48 markom Exp $
|
9 |
|
|
'\"
|
10 |
|
|
.so man.macros
|
11 |
|
|
.TH Tk_CreateErrorHandler 3 "" Tk "Tk Library Procedures"
|
12 |
|
|
.BS
|
13 |
|
|
.SH NAME
|
14 |
|
|
Tk_CreateErrorHandler, Tk_DeleteErrorHandler \- handle X protocol errors
|
15 |
|
|
.SH SYNOPSIS
|
16 |
|
|
.nf
|
17 |
|
|
\fB#include \fR
|
18 |
|
|
.sp
|
19 |
|
|
Tk_ErrorHandler
|
20 |
|
|
\fBTk_CreateErrorHandler\fR(\fIdisplay, error, request, minor, proc, clientData\fR)
|
21 |
|
|
.sp
|
22 |
|
|
\fBTk_DeleteErrorHandler\fR(\fIhandler\fR)
|
23 |
|
|
.SH ARGUMENTS
|
24 |
|
|
.AS "Tk_ErrorHandler" clientData
|
25 |
|
|
.AP Display *display in
|
26 |
|
|
Display whose errors are to be handled.
|
27 |
|
|
.AP int error in
|
28 |
|
|
Match only error events with this value in the \fIerror_code\fR
|
29 |
|
|
field. If -1, then match any \fIerror_code\fR value.
|
30 |
|
|
.AP int request in
|
31 |
|
|
Match only error events with this value in the \fIrequest_code\fR
|
32 |
|
|
field. If -1, then match any \fIrequest_code\fR value.
|
33 |
|
|
.AP int minor in
|
34 |
|
|
Match only error events with this value in the \fIminor_code\fR
|
35 |
|
|
field. If -1, then match any \fIminor_code\fR value.
|
36 |
|
|
.AP Tk_ErrorProc *proc in
|
37 |
|
|
Procedure to invoke whenever an error event is received for
|
38 |
|
|
\fIdisplay\fR and matches \fIerror\fR, \fIrequest\fR, and \fIminor\fR.
|
39 |
|
|
NULL means ignore any matching errors.
|
40 |
|
|
.AP ClientData clientData in
|
41 |
|
|
Arbitrary one-word value to pass to \fIproc\fR.
|
42 |
|
|
.AP Tk_ErrorHandler handler in
|
43 |
|
|
Token for error handler to delete (return value from a previous
|
44 |
|
|
call to \fBTk_CreateErrorHandler\fR).
|
45 |
|
|
.BE
|
46 |
|
|
|
47 |
|
|
.SH DESCRIPTION
|
48 |
|
|
.PP
|
49 |
|
|
\fBTk_CreateErrorHandler\fR arranges for a particular procedure
|
50 |
|
|
(\fIproc\fR) to be called whenever certain protocol errors occur on a
|
51 |
|
|
particular display (\fIdisplay\fR). Protocol errors occur when
|
52 |
|
|
the X protocol is used incorrectly, such as attempting to map a window
|
53 |
|
|
that doesn't exist. See the Xlib documentation for \fBXSetErrorHandler\fR
|
54 |
|
|
for more information on the kinds of errors that can occur.
|
55 |
|
|
For \fIproc\fR to be invoked
|
56 |
|
|
to handle a particular error, five things must occur:
|
57 |
|
|
.IP [1]
|
58 |
|
|
The error must pertain to \fIdisplay\fR.
|
59 |
|
|
.IP [2]
|
60 |
|
|
Either the \fIerror\fR argument to \fBTk_CreateErrorHandler\fR
|
61 |
|
|
must have been -1, or the \fIerror\fR argument must match
|
62 |
|
|
the \fIerror_code\fR field from the error event.
|
63 |
|
|
.IP [3]
|
64 |
|
|
Either the \fIrequest\fR argument to \fBTk_CreateErrorHandler\fR
|
65 |
|
|
must have been -1, or the \fIrequest\fR argument must match
|
66 |
|
|
the \fIrequest_code\fR field from the error event.
|
67 |
|
|
.IP [4]
|
68 |
|
|
Either the \fIminor\fR argument to \fBTk_CreateErrorHandler\fR
|
69 |
|
|
must have been -1, or the \fIminor\fR argument must match
|
70 |
|
|
the \fIminor_code\fR field from the error event.
|
71 |
|
|
.IP [5]
|
72 |
|
|
The protocol request to which the error pertains must have been
|
73 |
|
|
made when the handler was active (see below for more information).
|
74 |
|
|
.PP
|
75 |
|
|
\fIProc\fR should have arguments and result that match the
|
76 |
|
|
following type:
|
77 |
|
|
.CS
|
78 |
|
|
typedef int Tk_ErrorProc(
|
79 |
|
|
ClientData \fIclientData\fR,
|
80 |
|
|
XErrorEvent *\fIerrEventPtr\fR);
|
81 |
|
|
.CE
|
82 |
|
|
The \fIclientData\fR parameter to \fIproc\fR is a copy of the \fIclientData\fR
|
83 |
|
|
argument given to \fBTcl_CreateErrorHandler\fR when the callback
|
84 |
|
|
was created. Typically, \fIclientData\fR points to a data
|
85 |
|
|
structure containing application-specific information that is
|
86 |
|
|
needed to deal with the error. \fIErrEventPtr\fR is
|
87 |
|
|
a pointer to the X error event.
|
88 |
|
|
The procedure \fIproc\fR should return an integer value. If it
|
89 |
|
|
returns 0 it means that \fIproc\fR handled the error completely and there
|
90 |
|
|
is no need to take any other action for the error. If it returns
|
91 |
|
|
non-zero it means \fIproc\fR was unable to handle the error.
|
92 |
|
|
.PP
|
93 |
|
|
If a value of NULL is specified for \fIproc\fR, all matching errors
|
94 |
|
|
will be ignored: this will produce the same result as if a procedure
|
95 |
|
|
had been specified that always returns 0.
|
96 |
|
|
.PP
|
97 |
|
|
If more than more than one handler matches a particular error, then
|
98 |
|
|
they are invoked in turn. The handlers will be invoked in reverse
|
99 |
|
|
order of creation: most recently declared handler first.
|
100 |
|
|
If any handler returns 0, then subsequent (older) handlers will
|
101 |
|
|
not be invoked. If no handler returns 0, then Tk invokes X'es
|
102 |
|
|
default error handler, which prints an error message and aborts the
|
103 |
|
|
program. If you wish to have a default handler that deals with errors
|
104 |
|
|
that no other handler can deal with, then declare it first.
|
105 |
|
|
.PP
|
106 |
|
|
The X documentation states that ``the error handler should not call
|
107 |
|
|
any functions (directly or indirectly) on the display that will
|
108 |
|
|
generate protocol requests or that will look for input events.''
|
109 |
|
|
This restriction applies to handlers declared by \fBTk_CreateErrorHandler\fR;
|
110 |
|
|
disobey it at your own risk.
|
111 |
|
|
.PP
|
112 |
|
|
\fBTk_DeleteErrorHandler\fR may be called to delete a
|
113 |
|
|
previously-created error handler. The \fIhandler\fR argument
|
114 |
|
|
identifies the error handler, and should be a value returned by
|
115 |
|
|
a previous call to \fBTk_CreateEventHandler\fR.
|
116 |
|
|
.PP
|
117 |
|
|
A particular error handler applies to errors resulting
|
118 |
|
|
from protocol requests generated between
|
119 |
|
|
the call to \fBTk_CreateErrorHandler\fR and the call to
|
120 |
|
|
\fBTk_DeleteErrorHandler\fR. However, the actual callback
|
121 |
|
|
to \fIproc\fR may not occur until after the \fBTk_DeleteErrorHandler\fR
|
122 |
|
|
call, due to buffering in the client and server.
|
123 |
|
|
If an error event pertains to
|
124 |
|
|
a protocol request made just before calling \fBTk_DeleteErrorHandler\fR,
|
125 |
|
|
then the error event may not have been processed
|
126 |
|
|
before the \fBTk_DeleteErrorHandler\fR
|
127 |
|
|
call. When this situation arises, Tk will save information about
|
128 |
|
|
the handler and
|
129 |
|
|
invoke the handler's \fIproc\fR later when the error event
|
130 |
|
|
finally arrives.
|
131 |
|
|
If an application wishes to delete an error handler and know
|
132 |
|
|
for certain that all relevant errors have been processed,
|
133 |
|
|
it should first call \fBTk_DeleteErrorHandler\fR and then
|
134 |
|
|
call \fBXSync\fR; this will flush out any buffered requests and errors,
|
135 |
|
|
but will result in a performance penalty because
|
136 |
|
|
it requires communication to and from the X server. After the
|
137 |
|
|
\fBXSync\fR call Tk is guaranteed not to call any error
|
138 |
|
|
handlers deleted before the \fBXSync\fR call.
|
139 |
|
|
.PP
|
140 |
|
|
For the Tk error handling mechanism to work properly, it is essential
|
141 |
|
|
that application code never calls \fBXSetErrorHandler\fR directly;
|
142 |
|
|
applications should use only \fBTk_CreateErrorHandler\fR.
|
143 |
|
|
|
144 |
|
|
.SH KEYWORDS
|
145 |
|
|
callback, error, event, handler
|