XSetErrorHandler(3)
okay bestie, welcome to XSetErrorHandler(3) β the manual page from the XLIB FUNCTIONS section, and it's all about default error handlers. pull up a chair, we're getting into it. π
πΈ NAME πΈ
okay so the whole squad on this page is XSetErrorHandler, XGetErrorText, XDisplayName, XSetIOErrorHandler, XSetIOErrorExitHandler, and XGetErrorDatabaseText β and they're the default error handlers plus their little helper besties. no cap, that's the name section. π
β¨ SYNTAX β¨
int (*XSetErrorHandler(int (*handler)(Display *, XErrorEvent *)))();
int XGetErrorText(Display *display, int code, char *buffer_return, int
length);
char *XDisplayName(_Xconst char *string);
int (*XSetIOErrorHandler(int (*handler)(Display *)))();
void (*XSetIOErrorExitHandler(Display *display, void (*handler)(Display
*, void *), void *user_data))();
int XGetErrorDatabaseText(Display *display, _Xconst char *name, _Xconst
char *message, _Xconst char *default_string, char *buffer_return,
int length);
π ARGUMENTS π
buffer_returnβ returns the error description. that's the buffer where the error description comes back to you. πcodeβ specifies the error code for which you want to obtain a description.default_stringβ specifies the default error message if none is found in the database.displayβ specifies the connection to the X server.handlerβ specifies the program's supplied error handler.lengthβ specifies the size of the buffer.messageβ specifies the type of the error message.nameβ specifies the name of the application.stringβ specifies the character string.
π DESCRIPTION π
okay so here's the tea: Xlib generally calls the program's supplied error handler whenever an error is received. but it is not called on BadName errors from OpenFont, LookupColor, or AllocNamedColor protocol requests, and it's also not called on BadFont errors from a QueryFont protocol request. those errors generally get reflected back to the program through the procedural interface. because this condition is not assumed to be fatal, it is acceptable for your error handler to return; the returned value is ignored. however, your error handler should not call any functions (directly or indirectly) on the display that will generate protocol requests or that will look for input events. the previous error handler is returned. periodt. π
XGetErrorText copies a null-terminated string describing the specified error code into the specified buffer. the returned text is in the encoding of the current locale. it is recommended that you use this function to obtain an error description, because extensions to Xlib may define their own error codes and error strings. she's helpful like that. π
XDisplayName returns the name of the display that XOpenDisplay would attempt to use. if a NULL string is specified, XDisplayName looks in the environment for the display and returns the display name that XOpenDisplay would attempt to use. this makes it easier to report to the user precisely which display the program attempted to open when the initial connection attempt failed. literally so useful for debugging. π«Ά
XSetIOErrorHandler sets the fatal I/O error handler. Xlib calls the program's supplied error handler if any sort of system call error occurs (for example, the connection to the server was lost). this is assumed to be a fatal condition, and the called routine should normally not return. if the I/O error handler does return, the client process exits by default; this behavior may be altered with the XSetIOErrorExitHandler function. note that the previous error handler is returned. no cap, that's the fatal one. π
XGetErrorDatabaseText returns a null-terminated message (or the default message) from the error message database. Xlib uses this function internally to look up its error messages. the text in the default_string argument is assumed to be in the encoding of the current locale, and the text stored in the buffer_return argument is in the encoding of the current locale. π¦
the name argument should generally be the name of your application. the message argument should indicate which type of error message you want. if the name and message are not in the Host Portable Character Encoding, the result is implementation-dependent. Xlib uses three predefined βapplication namesβ to report errors. in these names, uppercase and lowercase matter. π
XProtoErrorβ the protocol error number is used as a string for themessageargument.XlibMessageβ these are the message strings that are used internally by the library.XRequestβ for a core protocol request, the major request protocol number is used for themessageargument. for an extension request, the extension name (as given byInitExtension) followed by a period (.) and the minor request protocol number is used for themessageargument. if no string is found in the error database, thedefault_stringis returned to the buffer argument.
π¦ SEE ALSO π¦
XOpenDisplay(3)XSynchronize(3)Xlib - C Language X Interface
π and that's the whole page, bestie β signed off with X Version 11 and libX11 1.8.14, plus all the source/version/date footer energy. stay slay and happy error-handling! π
π¦ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 Β· X11
- arch rolling: libx11 1.8.14-1 Β· MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms