Client Library Desires to Display HDF5 Error Stack Code Example:

(Display Error Stack Error Use Case Scenario)

/* This routine prints the error stack in two different ways, using the default
error printing routine and a custom error printing routine (below).  The parameter error_stack
can be H5E_DEFAULT for current stack or the object handle for an error stack converted by 
H5Eget_current_stack */
int Client_dump_error(hid_t error_stack)
{
	/* This call uses the default HDF5 error printing routine to display the error stack */
	H5Eprint(error_stack, stdout);

	/* This call uses a custom error printing routine to display the error stack */
	H5Ewalk(error_stack,H5E_WALK_UPWARD,Client_print_error,NULL);
}

/* This routine prints the information for an error on the error stack */
/* Note that it uses the following H5E_error_t struct, which is updated from
 * the current H5E_error_t:
 *
 * typedef struct H5E_error_t {
 *    hid_t 	  cls_id;	/* Error class ID		      */
 *    hid_t 	  maj_id;	/* Major error ID		      */
 *    hid_t       min_id;	/* Minor error ID		      */
 *    const char *func_name;	/* Function in which error occurred   */
 *    const char *file_name;	/* File in which error occurred       */
 *    unsigned	  line;		/* Line in file where error occurs    */
 *    const char *desc;		/* Optional supplied description      */
 * } H5E_error_t;
 *
 */
herr_t Client_print_error(int n, H5E_error_t *err_desc, void *cb_data)
{
        const char class_name[32];
        const char maj_name[32];
        const char min_name[32];
        
	/* Get the error class's name */
	H5Eget_class(err_desc->class,class_name,32);

	/* Get the major error description */
	H5Eget_mesg(err_desc->maj_num,maj_name,32);

	/* Get the minor error description */
	H5Eget_mesg(err_desc->min_num,min_num,32);

	/* Print error information */
	printf("Error Stack Position: %d\n",n);
	printf("Error Class: %s\n",class_name);
	printf("Major Error Description: %s\n",maj_name);
	printf("Minor Error Description: %s\n",min_name);
	printf("File Name: %s\n",err_desc->file_name);
	printf("Function Name: %s\n",err_desc->func_name);
	printf("Line #: %u\n",err_desc->line);
	printf("Error Description: %s\n",err_desc->desc);
}

The output from the default error printing routine for a failure in the H5Dwrite routine is shown below(this relies on the previous two examples: Register Client Library and Push Error). For each different class, the first line tells the information about the library name, version number and thread ID.

HDF5-DIAG: Error detected in HDF5 library version: 1.5.62 thread 0.  
	#002: H5D.c line 1342 in H5Dwrite(): not a dataset
		class(07): HDF5 Library
		major(12): invalid arguments to routine
		minor(23): incorrect type found
A_CLIENT-DIAG: Error detected in A_CLIENT library version: 1.0 thread 0.
	#001: client_io.c line 123 in Client_do_write(): H5Dwrite failed
		class(07): Client Library
		major(43): Errors on I/O
		minor(97): Error in HDF5