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