See XSetErrorHandler. If an error event is received and the global variable x-error-handler is bound to a compound procedure, this procedure is invoked with the following arguments: a display, the serial number of the failed request (an integer), the error code (either an integer or one of the symbols bad-request, bad-value, bad-window, bad-pixmap, bad-atom, bad-cursor, bad-font, bad-match, bad-drawable, bad-access, bad-alloc, bad-color, bad-gcontext, bad-id-choice, bad-name, bad-length, or bad-implementation), the major and minor op-code of the failed request (integers), and a resource-ID (an integer).
If an error event is received and this variable is not bound to a compound procedure, the Xlib default error handler is invoked. The initial value of this variable is the empty list.
If a fatal I/O error occurs and the global variable
x-fatal-error-handler is bound to a compound procedure, this
procedure is invoked with a display as argument.
The procedure must invoke exit.
If a fatal error occurs and this variable is not bound to a
compound procedure, or if the procedure returns, the Xlib default
fatal error handler is invoked and the interpreter terminates with
an exit code of 1.
The initial value of this variable is the empty list.