A list of error codes is included at the end of this chapter.
if (<general HDF function() >= FAIL) { <HDF error reporting API routines> }
status = <general HDF function( ); if (status == FAIL) { <HDF error reporting API routines> }
12.3.1 Writing Errors to a File: HEprint
HEprint writes the errors on the stack to the specified file. There are four sections of an HEprint error report:
C: HEprint(stream, level); FORTRAN: status = heprnt(level)
The stream parameter is a UNIX file handle indicating the output stream the error information will be written to. The level parameter specifies the amount of error information to report. In Fortran-77, HEprint always writes to the standard error stream, or stderr, therefore the only parameter is level.
f = fopen("errors", "w"); HEprint(f, 0);
HDF error: <error opening file> Detected in Hopen() [hfile.c line 305]
12.3.2 Returning the Code of the Nth Most Recent Error: HEvalue
HEvalue returns the error code for the nth most recent error and is only available as a C routine. The error_stack_offset parameter specifies the number of errors to regress from the top of the error stack.
C: status = HEvalue(error_stack_offset);
12.3.3 Returning the Description of an Error Code: HEstring
HEstring returns the error description associated with the error code specified by the error_code parameter as a character string. As with HEvalue, HEstring is only available in the C HDF library.
C: error_string = HEstring(error_code);
EXAMPLE 1. Writing Errors to a Console Window
The following C code fragment will copy errors from the stack to a console window.
main( ) { int32 i, e; const char *str; ... i = 0; while ((e = HEvalue(i)) != DFE_NONE) { str = HEstring(e); <device-specific code to print the string to a console> i++ ... }