https://stackoverflow.com/questions/20107649/how-to-catch-x-errors

You need to use XSetErrorHandler to specify an error handler e.g.

XSetErrorHandler(handler);

The error handler is

int handler(Display * d, XErrorEvent * e)
{
    std::cerr << "Error code: " << e->error_code << std::endl;
    return 0;
}

