Push Client Library Error onto HDF5 Error Stack Code Example
Author: Quincey Koziol

### Client Library Desires to Push an Error onto HDF5 Error Stack Code Example:

(Push Error Use Case Scenario)

    /* Client error class ID */
    hid_t CLIENT_ERROR;

    /* Major error code IDs */
    hid_t CLIENT_ERR_MAJOR_IO;		/* Errors on I/O */
    hid_t CLIENT_ERR_MAJOR_FILE;	/* Errors on file access */
       .
       .
       .

    /* Minor error code IDs */
    hid_t CLIENT_ERR_MINOR_PERM;	/* Invalid permissions */
    hid_t CLIENT_ERR_MINOR_HDF5;	/* Error in HDF5 */
       .
       .
       .

    int Client_do_write
    {
    	/* Create strings to hold function name for error reporting and a file name */
    	const char *FUNC="Client_do_write";
            const char *file="a_file";

    	/* Set up client write information, etc. */
    		.
    		.
    		.

    	/* Check permissions on writing at client level */
    	/* (This shows client library pushing error onto current stack by itself) */
    	if(...)
    	{
    		/* Push client error onto error stack */
    		H5Epush(H5E_DEFAULT,__FILE__,FUNC,__LINE__,CLIENT_ERR_MAJ_IO,CLIENT_ERR_MINOR_PERM,"Can't write to this object");

    		/* Indicate error occurred in function */
    		return(0);
    	}

    		.
    		.
    		.

    	/* Make call to HDF5 I/O routine */
    	/* (This shows client library pushing error onto current stack on top of HDF5 errors) */
    	if(H5Dwrite(dset_id, mem_type_id, mem_space_id, file_space_id, dset_xfer_plist_id, buf)<0)
    	{
    		/* Push client error onto error stack */
    		H5Epush(H5E_DEFAULT,__FILE__,FUNC,__LINE__,CLIENT_ERR_MAJ_IO,CLIENT_ERR_MINOR_HDF5,"H5Dwrite failed");

    		/* Indicate error occurred in function */
    		return(0);
    	}
    		.
    		.
    		.

            /* Make a system call */
            /* (This shows client library pushing error onto current stack with additional message
             * generated during run time)
             */
            if(open(file, O_RDONLY)<0) {
                    const char* mesg = strerror(errno);

                    /* Push client error onto error stack */
                    H5Epush(H5E_DEFAULT,__FILE__,FUNC, __LINE__,CLIENT_ERR_MAJ_IO,CLIENT_ERR_MINOR_OPEN,"Can't open system file, errno=%s", mesg);

                    /* Indicate error occurred in this function */
                    return(0);
            }

    	/* Successful return from function */
    	return(1);
    }