GR_EVENT_ERROR

Name

GR_EVENT_ERROR -- Error event structure

Synopsis

typedef struct 
{
    GR_EVENT_TYPE   type;
    GR_FUNC_NAME    name;
    GR_ERROR        code;
    GR_ID           id;
} GR_EVENT_ERROR;
  

Description

The GR_EVENT_ERROR structure is used by nano-X to report runtime errors. Some errors are system errors, such as GR_ERROR_MALLOC_FAILED which indicates that a memory allocation failed. Other error types are program errors, such as GR_ERROR_ILLEGAL_ON_ROOT_WINDOW which will occur if for example the program tries to move the root window.

Fields

TypeNameDescription
GR_EVENT_TYPEtypeThe event type will be GR_EVENT_TYPE_ERROR.
GR_FUNC_NAMEnameThe name of the function in which the error occured.
GR_ERRORcodeThe type of error that occured.
GR_IDidThe window ID of the window that an error occured on, if the event is related to a window. The GC ID of the graphics context that an error occured on if the error occured on a GC. Set to 0 if the error is not related to a window or a GC.

Example

The following example shows a typical error handler.

Example 3-1. Using GR_EVENT_ERROR

 
char *error_strings[] = { GR_ERROR_STRINGS };  /* See nano-X.h */

void  process_error_event (GR_EVENT_ERROR *event)
{
    printf ("NANO-X ERROR (function %s): ", event->name);
    printf (error_strings[event->code], event->id);
    printf ("\n");
    fflush (stdout);

    GrClose();
    exit (1);
}

See Also

GR_EVENT, GrDefaultErrorHandler().