HDF5 documents and links 
Introduction to HDF5 
HDF5 User Guide 
And in this document, the HDF5 Reference Manual  
H5   H5A   H5D   H5E   H5F   H5G   H5I   H5P  
H5R   H5S   H5T   H5Z   Tools   Datatypes  

H5E: Error Interface

Error API Functions

These functions provide error handling capabilities in the HDF5 environment.

The C Interfaces:
             

Alphabetical Listing
             

The FORTRAN90 Interfaces:
In general, each FORTRAN90 subroutine performs exactly the same task as the corresponding C function.
             

The Error interface provides error handling in the form of a stack. The FUNC_ENTER() macro clears the error stack whenever an interface function is entered. When an error is detected, an entry is pushed onto the stack. As the functions unwind, additional entries are pushed onto the stack. The API function will return some indication that an error occurred and the application can print the error stack.

Certain API functions in the H5E package, such as H5Eprint, do not clear the error stack. Otherwise, any function which does not have an underscore immediately after the package name will clear the error stack. For instance, H5Fopen clears the error stack while H5F_open does not.

An error stack has a fixed maximum size. If this size is exceeded then the stack will be truncated and only the inner-most functions will have entries on the stack. This is expected to be a rare condition.

Each thread has its own error stack, but since multi-threading has not been added to the library yet, this package maintains a single error stack. The error stack is statically allocated to reduce the complexity of handling errors within the H5E package.


Name: H5Eauto_is_stack
Signature:
herr_t H5Eauto_is_stack(hid_t estack_id, unsigned *is_stack)
Purpose:
Determines type of error stack.
Description:
H5Eauto_is_stack determines whether the error auto reporting function for an error stack conforms to the H5E_auto_stack_t typedef or the H5E_auto_t typedef.

The is_stack parameter is set to 11 if the error stack conforms to H5E_auto_stack_t and 0 for if H5E_auto_t.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:

Name: H5Eclear
Signature (deprecated):
herr_t H5Eclear(void)
Purpose:
Clears the error stack for the current thread.
Description:
H5Eclear clears the error stack for the current thread.

The stack is also cleared whenever an API function is called, with certain exceptions (for instance, H5Eprint).

H5Eclear can fail if there are problems initializing the library.

Note: As of HDF5 Release 1.8, H5Eclear_stack replaces H5Eclear and H5Eclear is designated a deprecated function. H5Eclear may be removed from the library at a future release.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface: h5eclear_f
SUBROUTINE h5eclear_f(hdferr) 
  IMPLICIT NONE
  INTEGER, INTENT(OUT) :: hdferr  ! Error code

END SUBROUTINE h5eclear_f
	

Name: H5Eclear_stack
Signature:
herr_t H5Eclear_stack(hid_t estack_id)
Purpose:
Clears the error stack for the current thread.
Description:
H5Eclear_stack clears the error stack specified by estack_id for the current thread.

If the value of estack_id is H5E_DEFAULT, the current current error stack will be cleared.

The current error stack is also cleared whenever an API function is called, with certain exceptions (for instance, H5Eprint).

H5Eclear_stack can fail if there are problems initializing the library.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eclose_msg
Signature:
herr_t H5Eclose_msg(hid_t mesg_id)
Purpose:
Closes an error message identifier.
Description:
H5Eclose_msg closes an error message identifier., which can be either a major or minor message.
Parameters:
Returns:
Returns a non-negative value on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eclose_stack
Signature:
herr_t H5Eclose_stack(hid_t estack_id)
Purpose:
Closes object handle for error stack.
Description:
H5Eclose_stack closes the object handle for an error stack and releases its resources. H5E_DEFAULT cannot be closed.
Parameters:
Returns:
Returns a non-negative value on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Ecreate_msg
Signature:
hid_t H5Ecreate_msg(hid_t class, H5E_type_t msg_type, const char* mesg)
Purpose:
Add major error message to an error class.
Description:
H5Ecreate_msg adds an error message to an error class defined by client library or application program. The error message can be either major or minor which is indicated by parameter msg_type.
Parameters:
Returns:
Returns a message identifier on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eget_auto
Signature (deprecated):
herr_t H5Eget_auto(H5E_auto_t * func, void **client_data )
Purpose:
Returns the current settings for the automatic error stack traversal function and its data.
Description:
H5Eget_auto returns the current settings for the automatic error stack traversal function, func, and its data, client_data. Either (or both) arguments may be null in which case the value is not returned.

Note: As of HDF5 Release 1.8, H5Eget_auto_stack replaces H5Eget_auto and H5Eget_auto is designated a deprecated function. H5Eget_auto may be removed from the library at a future release.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eget_auto_stack
Signature:
herr_t H5Eget_auto_stack( hid_t estack_id, H5E_auto_stack_t * func, void **client_data )
Purpose:
Returns the current settings for the automatic error stack traversal function and its data.
Description:
H5Eget_auto_stack returns the current settings for the automatic error stack traversal function, func, and its data, client_data, that are associated with the error stack specified by estack_id.

Either or both of the func and client_data arguments may be null, in which case the value is not returned.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eget_class_name
Signature:
ssize_t H5Eget_class_name(hid_t class_id, char* name, size_t size)
Purpose:
Retrieves error class name.
Description:
H5Eget_class_name retrieves the name of the error class specified by the class identifier. If non-NULL pointer is passed in for name and size is greater than zero, the class name of size long is returned. The length of the error class name is also returned. If NULL is passed in as name, only the length of class name is returned. If zero is returned, it means no name. User is responsible for allocated enough buffer for the name.
Parameters:
Returns:
Returns non-negative value as on success; otherwise returns negative value.
Fortran90 Interface:
None.

Name: H5Eget_current_stack
Signature:
hid_t H5Eget_current_stack(void)
Purpose:
Registers the current error stack.
Description:
H5Eget_current_stack registers the current error stack, returns an object identifier, and clears the current error stack. An empty error stack will also be assigned an identifier.
Parameters:
Returns:
Returns the identifier of the current error stack on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eget_major
Signature (deprecated):
const char * H5Eget_major(H5E_major_t n)
Purpose:
Returns a character string describing an error specified by a major error number.
Description:
Given a major error number, H5Eget_major returns a constant character string that describes the error.

Note: As of HDF5 Release 1.8, H5Eget_msg replaces H5Eget_major and H5Eget_major is designated a deprecated function. H5Eget_major may be removed from the library at a future release.

Parameters:
Returns:
Returns a character string describing the error if successful. Otherwise returns "Invalid major error number."
Fortran90 Interface: h5eget_major_f
SUBROUTINE h5eget_major_f(error_no, name, hdferr)
  INTEGER, INTENT(IN) :: error_no         !Major error number
  CHARACTER(LEN=*), INTENT(OUT) :: name   ! File name
  INTEGER, INTENT(OUT) :: hdferr          ! Error code

END SUBROUTINE h5eget_major_f
	

Name: H5Eget_minor
Signature (deprecated):
const char * H5Eget_minor(H5E_minor_t n)
Purpose:
Returns a character string describing an error specified by a minor error number.
Description:
Given a minor error number, H5Eget_minor returns a constant character string that describes the error.

Note: As of HDF5 Release 1.8, H5Eget_msg replaces H5Eget_minor and H5Eget_minor is designated a deprecated function. H5Eget_minor may be removed from the library at a future release.

Parameters:
Returns:
Returns a character string describing the error if successful. Otherwise returns "Invalid minor error number."
Fortran90 Interface: h5eget_minor_f
SUBROUTINE h5eget_minor_f(error_no, name, hdferr)
  INTEGER, INTENT(IN) :: error_no         !Major error number
  CHARACTER(LEN=*), INTENT(OUT) :: name   ! File name
  INTEGER, INTENT(OUT) :: hdferr          ! Error code

END SUBROUTINE h5eget_minor_f
	

Name: H5Eget_msg
Signature:
ssize_t H5Eget_msg(hid_t mesg_id, H5E_type_t* mesg_type, char* mesg, size_t size)
Purpose:
Retrieves an error message.
Description:
H5Eget_msg retrieves the error message including its length and type. The error message is specified by mesg_id. User is responsible for passing in enough buffer for the message. If mesg is not NULL and size is greater than zero, the error message of size long is returned. The length of the message is also returned. If NULL is passed in as mesg, only the length and type of the message is returned. If the return value is zero, it means no message.
Parameters:
Returns:
Returns the size of the error message in bytes on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eget_num
Signature:
ssize_t H5Eget_num(hid_t estack_id)
Purpose:
Retrieves the number of error messages in an error stack.
Description:
H5Eget_num retrieves the number of error records in the error stack specified by estack_id (including major, minor messages and description).
Parameters:
Returns:
Returns a non-negative value on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Epop
Signature:
herr_t H5Epop(hid_t estack_id, size_t count)
Purpose:
Deletes specified number of error messages from the error stack.
Description:
H5Epop deletes the number of error records specified in count from the top of the error stack specified by estack_id (including major, minor messages and description). The number of error messages to be deleted is specified by count.
Parameters:
Returns:
Returns a non-negative value on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eprint
Signature (deprecated):
herr_t H5Eprint(FILE * stream)
Purpose:
Prints the error stack in a default manner.
Description:
H5Eprint prints the error stack on the specified stream, stream. Even if the error stack is empty, a one-line message will be printed:
     HDF5-DIAG: Error detected in thread 0.

H5Eprint is a convenience function for H5Ewalk with a function that prints error messages. Users are encouraged to write their own more specific error handlers.

Note: As of HDF5 Release 1.8, H5Eprint_stack replaces H5Eprint and H5Eprint is designated a deprecated function. H5Eprint may be removed from the library at a future release.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface: h5eprint_f
SUBROUTINE h5eprint_f(hdferr, name)
  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: name ! File name
  INTEGER, INTENT(OUT) :: hdferr                 ! Error code

END SUBROUTINE h5eprint_f
	

Name: H5Eprint_stack
Signature:
herr_t H5Eprint( hid_t estack_id, FILE * stream)
Purpose:
Prints the error stack in a default manner.
Description:
H5Eprint_stack prints the error stack specified by estack_id on the specified stream, stream. Even if the error stack is empty, a one-line message of the following form will be printed:
     HDF5-DIAG: Error detected in HDF5 library version: 1.5.62 thread 0.

A similar line will appear before the error messages of each error class stating the library name, library version number, and thread identifier.

If estack_id is H5E_DEFAULT, the current error stack will be printed.

H5Eprint_stack is a convenience function for H5Ewalk_stack with a function that prints error messages. Users are encouraged to write their own more specific error handlers.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Epush
Signature (deprecated):
herr_t H5Epush( const char *file, const char *func, unsigned line, H5E_major_t maj_num, H5E_minor_t min_num, const char *str )
Purpose:
Pushes new error record onto error stack.
Description:
H5Epush pushes a new error record onto the error stack for the current thread.

The error has major and minor numbers maj_num and min_num, the function func where the error was detected, the name of the file file where the error was detected, the line line within that file, and an error description string str.

The function name, filename, and error description strings must be statically allocated.

Note: As of HDF5 Release 1.8, H5Epush_stack replaces H5Epush and H5Epush is designated a deprecated function. H5Epush may be removed from the library at a future release.

Parameters, H5Epush:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Epush_stack
Signature:
herr_t H5Epush_stack( hid_t estack_id, const char *file, const char *func, unsigned line, hid_t class_id, hid_t major_id, hid_t minor_id, const char *msg, ...)
Purpose:
Pushes new error record onto error stack.
Description:
H5Epush_stack pushes a new error record onto the error stack for the current thread.

The error record contains the error class identifier class_id, the major and minor message identifiers major_id and minor_id, the function name func where the error was detected, the filename file and line number line within that file where the error was detected, and an error description msg.

The major and minor errors must be in the same error class.

The function name, filename, and error description strings must be statically allocated.

msg can be a format control string with additional arguments. This design of appending additional arguments is similar to the system and C functions printf and fprintf.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eregister_class
Signature:
hid_t H5Eregister_class(const char* cls_name, const char* lib_name, const char* version)
Purpose:
Registers a client library or application program to HDF5 error API.
Description:
H5Eregister_class registers a client library or application program to HDF5 error API so that the client library or application program can report error together with HDF5 library. It receives an identifier for this error class for further error operations. The library name and version number will be printed out in the error message as preamble.
Parameters:
Returns:
Returns a class identifier on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eset_auto
Signature (deprecated):
herr_t H5Eset_auto(H5E_auto_t func, void *client_data )
Purpose:
Turns automatic error printing on or off.
Description:
H5Eset_auto turns on or off automatic printing of errors. When turned on (non-null func pointer), any API function which returns an error indication will first call func, passing it client_data as an argument.

When the library is first initialized the auto printing function is set to H5Eprint (cast appropriately) and client_data is the standard error stream pointer, stderr.

Automatic stack traversal is always in the H5E_WALK_DOWNWARD direction.

Note: As of HDF5 Release 1.8, H5Eset_auto_stack replaces H5Eset_auto and H5Eset_auto is designated a deprecated function. H5Eset_auto may be removed from the library at a future release.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface: h5eset_auto_f
SUBROUTINE h5eset_auto_f(printflag, hdferr)
  INTEGER, INTENT(IN) :: printflag  !flag to turn automatic error
                                    !printing on or off
                                    !possible values are:
                                    !printon (1)
                                    !printoff(0)
  INTEGER, INTENT(OUT) :: hdferr    ! Error code

END SUBROUTINE h5eset_auto_f
	

Name: H5Eset_auto_stack
Signature:
herr_t H5Eset_auto_stack( hid_t estack_id, H5E_auto_stack_t func, void *client_data )
Purpose:
Turns automatic error printing on or off.
Description:
H5Eset_auto_stack turns on or off automatic printing of errors for the error stack specified with estack_id. An estack_id value of H5E_DEFAULT indicates the current stack.

When automatic printing is turned on, by the use of a non-null func pointer, any API function which returns an error indication will first call func, passing it client_data as an argument.

When the library is first initialized, the auto printing function is set to H5Eprint_stack (cast appropriately) and client_data is the standard error stream pointer, stderr.

Automatic stack traversal is always in the H5E_WALK_DOWNWARD direction.

Automatic error printing is turned off with a H5Eset_auto_stack call with a NULL func pointer.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface: h5eset_auto_f
None.

Name: H5Eset_current_stack
Signature:
herr_t H5Eset_current_stack(hid_t estack_id)
Purpose:
Replaces the current error stack.
Description:
H5Eset_current_stack replaces the content of the current error stack with a copy of the content of error stack specified by estack_id.
Parameters:
Returns:
Returns a non-negative value on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Eunregister_class
Signature:
herr_t H5Eunregister_class(hid_t class_id)
Purpose:
Removes an error class.
Description:
H5Eunregister_class removes the error class specified by class_id. All the major and minor errors in this class will also be closed.
Parameters:
Returns:
Returns a non-negative value on success; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Ewalk
Signature (deprecated):
herr_t H5Ewalk(H5E_direction_t direction, H5E_walk_t func, void * client_data )
Purpose:
Walks the error stack for the current thread, calling a specified function.
Description:
H5Ewalk walks the error stack for the current thread and calls the specified function for each error along the way.

direction determines whether the stack is walked from the inside out or the outside in. A value of H5E_WALK_UPWARD means begin with the most specific error and end at the API; a value of H5E_WALK_DOWNWARD means to start at the API and end at the inner-most function where the error was first detected.

func will be called for each error in the error stack. Its arguments will include an index number (beginning at zero regardless of stack traversal direction), an error stack entry, and the client_data pointer passed to H5E_print. The H5E_walk_t prototype is as follows:

typedef herr_t (*H5E_walk_t)(int n, H5E_error_t *err_desc, void *client_data)

where the parameters have the following meanings:

int n
Indexed position of the error in the stack.
H5E_error_t *err_desc
Pointer to a data structure describing the error. (This structure is currently described only in the source code file hdf5/src/H5Epublic.h. That file also contains the definitive list of major and minor error codes. That information will eventually be presented as an appendix to this Reference Manual.)
void *client_data
Pointer to client data in the format expected by the user-defined function.

H5Ewalk can fail if there are problems initializing the library.

Note: As of HDF5 Release 1.8, H5Ewalk_stack replaces H5Ewalk and H5Ewalk is designated a deprecated function. H5Ewalk may be removed from the library at a future release.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Ewalk_stack
Signature:
herr_t H5Ewalk_stack( hid_t estack_id, H5E_direction_t direction, H5E_walk_t func, void * client_data )
Purpose:
Walks the error stack for the current thread, calling a specified function.
Description:
H5Ewalk_stack walks the error stack specified by estack_id for the current thread and calls the function specified in func for each error along the way.

If the value of estack_id is H5E_DEFAULT, then H5Ewalk_stack walks the current error stack.

direction specifies whether the stack is walked from the inside out or the outside in. A value of H5E_WALK_UPWARD means to begin with the most specific error and end at the API; a value of H5E_WALK_DOWNWARD means to start at the API and end at the innermost function where the error was first detected.

func, a function compliant with the H5E_walk_t prototype, will be called for each error in the error stack. Its arguments will include an index number n (beginning at zero regardless of stack traversal direction), an error stack entry err_desc, and the client_data pointer passed to H5E_print. The H5E_walk_t prototype is as follows:

typedef herr_t (*H5E_walk_t)(int n, H5E_error_t *err_desc, void *client_data)

where the parameters have the following meanings:

int n
Indexed position of the error in the stack.
H5E_error_t *err_desc
Pointer to a data structure describing the error. (This structure is currently described only in the source code file hdf5/src/H5Epublic.h. That file also contains the definitive list of major and minor error codes; that information will eventually be presented as an appendix to this HDF5 Reference Manual.)
void *client_data
Pointer to client data in the format expected by the user-defined function.

H5Ewalk_stack can fail if there are problems initializing the library.

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

Name: H5Ewalk_cb
Signature:
herr_t H5Ewalk_cb(int n, H5E_error_t *err_desc, void *client_data )
Purpose:
Default error stack traversal callback function that prints error messages to the specified output stream.
Description:
H5Ewalk_cb is a default error stack traversal callback function that prints error messages to the specified output stream. It is not meant to be called directly but rather as an argument to the H5Ewalk function. This function is called also by H5Eprint. Application writers are encouraged to use this function as a model for their own error stack walking functions.

n is a counter for how many times this function has been called for this particular traversal of the stack. It always begins at zero for the first error on the stack (either the top or bottom error, or even both, depending on the traversal direction and the size of the stack).

err_desc is an error description. It contains all the information about a particular error.

client_data is the same pointer that was passed as the client_data argument of H5Ewalk. It is expected to be a file pointer (or stderr if NULL).

Parameters:
Returns:
Returns a non-negative value if successful; otherwise returns a negative value.
Fortran90 Interface:
None.

HDF5 documents and links 
Introduction to HDF5 
HDF5 User Guide 
And in this document, the HDF5 Reference Manual  
H5IM   H5LT   H5PT   H5TB  
H5   H5A   H5D   H5E   H5F   H5G   H5I   H5P  
H5R   H5S   H5T   H5Z   Tools   Datatypes  

HDF Help Desk
Describes HDF5 Release 1.7, the unreleased development branch; working toward HDF5 Release 1.8.0