Debian Codegraph @

pod/pTk/CrtErrHdlr.pod

raw
1 # Copyright (c) 1990 The Regents of the University of California.
2 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
3 # See the file "license.terms" for information on usage and redistribution
4 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5 #
6 #
7
8 =head1 NAME
9
10 Tk_CreateErrorHandler, Tk_DeleteErrorHandler - handle X protocol errors
11
12 =for category C Programming
13
14 =head1 SYNOPSIS
15
16 B<#include E<lt>tk.hE<gt>>
17
18 Tk_ErrorHandler
19 B<Tk_CreateErrorHandler>(I<display, error, request, minor, proc, clientData>)
20
21 B<Tk_DeleteErrorHandler>(I<handler>)
22
23 =head1 ARGUMENTS
24
25 =over 4
26
27 =item Display *display (in)
28
29 Display whose errors are to be handled.
30
31 =item int error (in)
32
33 Match only error events with this value in the I<error_code>
34 field. If -1, then match any I<error_code> value.
35
36 =item int request (in)
37
38 Match only error events with this value in the I<request_code>
39 field. If -1, then match any I<request_code> value.
40
41 =item int minor (in)
42
43 Match only error events with this value in the I<minor_code>
44 field. If -1, then match any I<minor_code> value.
45
46 =item Tk_ErrorProc *proc (in)
47
48 Procedure to invoke whenever an error event is received for
49 I<display> and matches I<error>, I<request>, and I<minor>.
50 NULL means ignore any matching errors.
51
52 =item ClientData clientData (in)
53
54 Arbitrary one-word value to pass to I<proc>.
55
56 =item Tk_ErrorHandler handler (in)
57
58 Token for error handler to delete (return value from a previous
59 call to B<Tk_CreateErrorHandler>).
60
61 =back
62
63 =head1 DESCRIPTION
64
65 B<Tk_CreateErrorHandler> arranges for a particular procedure
66 (I<proc>) to be called whenever certain protocol errors occur on a
67 particular display (I<display>). Protocol errors occur when
68 the X protocol is used incorrectly, such as attempting to map a window
69 that doesn't exist. See the Xlib documentation for B<XSetErrorHandler>
70 for more information on the kinds of errors that can occur.
71 For I<proc> to be invoked
72 to handle a particular error, five things must occur:
73
74 =over 4
75
76 =item [1]
77
78 The error must pertain to I<display>.
79
80 =item [2]
81
82 Either the I<error> argument to B<Tk_CreateErrorHandler>
83 must have been -1, or the I<error> argument must match
84 the I<error_code> field from the error event.
85
86 =item [3]
87
88 Either the I<request> argument to B<Tk_CreateErrorHandler>
89 must have been -1, or the I<request> argument must match
90 the I<request_code> field from the error event.
91
92 =item [4]
93
94 Either the I<minor> argument to B<Tk_CreateErrorHandler>
95 must have been -1, or the I<minor> argument must match
96 the I<minor_code> field from the error event.
97
98 =item [5]
99
100 The protocol request to which the error pertains must have been
101 made when the handler was active (see below for more information).
102
103 I<Proc> should have arguments and result that match the
104 following type:
105
106 typedef int Tk_ErrorProc(
107 ClientData clientData,
108 XErrorEvent *errEventPtr);
109
110 The I<clientData> parameter to I<proc> is a copy of the I<clientData>
111 argument given to B<Tcl_CreateErrorHandler> when the callback
112 was created. Typically, I<clientData> points to a data
113 structure containing application-specific information that is
114 needed to deal with the error. I<ErrEventPtr> is
115 a pointer to the X error event.
116 The procedure I<proc> should return an integer value. If it
117 returns 0 it means that I<proc> handled the error completely and there
118 is no need to take any other action for the error. If it returns
119 non-zero it means I<proc> was unable to handle the error.
120
121 If a value of NULL is specified for I<proc>, all matching errors
122 will be ignored: this will produce the same result as if a procedure
123 had been specified that always returns 0.
124
125 If more than more than one handler matches a particular error, then
126 they are invoked in turn. The handlers will be invoked in reverse
127 order of creation: most recently declared handler first.
128 If any handler returns 0, then subsequent (older) handlers will
129 not be invoked. If no handler returns 0, then Tk invokes X'es
130 default error handler, which prints an error message and aborts the
131 program. If you wish to have a default handler that deals with errors
132 that no other handler can deal with, then declare it first.
133
134 The X documentation states that ``the error handler should not call
135 any functions (directly or indirectly) on the display that will
136 generate protocol requests or that will look for input events.''
137 This restriction applies to handlers declared by B<Tk_CreateErrorHandler>;
138 disobey it at your own risk.
139
140 B<Tk_DeleteErrorHandler> may be called to delete a
141 previously-created error handler. The I<handler> argument
142 identifies the error handler, and should be a value returned by
143 a previous call to B<Tk_CreateEventHandler>.
144
145 A particular error handler applies to errors resulting
146 from protocol requests generated between
147 the call to B<Tk_CreateErrorHandler> and the call to
148 B<Tk_DeleteErrorHandler>. However, the actual callback
149 to I<proc> may not occur until after the B<Tk_DeleteErrorHandler>
150 call, due to buffering in the client and server.
151 If an error event pertains to
152 a protocol request made just before calling B<Tk_DeleteErrorHandler>,
153 then the error event may not have been processed
154 before the B<Tk_DeleteErrorHandler>
155 call. When this situation arises, Tk will save information about
156 the handler and
157 invoke the handler's I<proc> later when the error event
158 finally arrives.
159 If an application wishes to delete an error handler and know
160 for certain that all relevant errors have been processed,
161 it should first call B<Tk_DeleteErrorHandler> and then
162 call B<XSync>; this will flush out any buffered requests and errors,
163 but will result in a performance penalty because
164 it requires communication to and from the X server. After the
165 B<XSync> call Tk is guaranteed not to call any error
166 handlers deleted before the B<XSync> call.
167
168 For the Tk error handling mechanism to work properly, it is essential
169 that application code never calls B<XSetErrorHandler> directly;
170 applications should use only B<Tk_CreateErrorHandler>.
171
172 =back
173
174 =head1 KEYWORDS
175
176 callback, error, event, handler