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