3.4. Error Handling

Errors in XOSD are handled in a very similar way to errors in the base C libraries. All XOSD functions, except for xosd_create, return an integer value; if the value is -1 an error occurred. For example, the following code checks to see if the call to the xosd_show function was successful, and calls exit if it was not.

if (xosd_show(osd) == -1)
  {
     /* An error occurred */
     exit(1);
  }

To know why the called failed you need to print out the value of the xosd_error variable, as is done in the following example.

if (xosd_show(osd) == -1)
  {
     /* An error occurred */
     fprintf(stderr, "Could not show XOSD window: %s\n", xosd_error);
     exit(1);
  }

The xosd_create function returns a pointer rather than an integer. To indicate an error the pointer returned by xosd_create is set to NULL. The first example in Section 3.1, “Our First XOSD Program” shows how to check if a call to xosd_create was successful.