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 the message argument.
  • 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 the message argument. for an extension request, the extension name (as given by InitExtension) followed by a period (.) and the minor request protocol number is used for the message argument. if no string is found in the error database, the default_string is returned to the buffer argument.

πŸ¦‹ SEE ALSO πŸ¦‹


πŸ’– 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