typedef struct { GR_EVENT_TYPE type; GR_FUNC_NAME name; GR_ERROR code; GR_ID id; } GR_EVENT_ERROR; |
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.
Type | Name | Description |
---|---|---|
GR_EVENT_TYPE | type | The event type will be GR_EVENT_TYPE_ERROR. |
GR_FUNC_NAME | name | The name of the function in which the error occured. |
GR_ERROR | code | The type of error that occured. |
GR_ID | id | The 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. |
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); } |