H3 does it's best to be robust to system failures or unexpected inputs, but some times these cannot be recovered from. H3's way of doing this is to return an error code to the caller.
This code example checks for an error when calling an H3 function and prints a message if the call did not succeed:
The type returned by most H3 functions is
H3Error, a 32 bit integer type with the following properties:
H3Errorwill be an integer type of 32 bits, i.e.
H3Errorwith value 0 indicates success (no error).
H3Errorvalue will set the most significant bit.
- As a result of these properties, no
H3Errorvalue will set the bits that correspond with the Mode bit field in an
32 bit return codes with the high bit never set allows for mixing error codes and resulting indexes if desired by the application, after copying the error codes into the result buffer.
|0||E_SUCCESS||Success (no error)|
|1||E_FAILED||The operation failed but a more specific error is not available|
|2||E_DOMAIN||Argument was outside of acceptable range (when a more specific error code is not available)|
|3||E_LATLNG_DOMAIN||Latitude or longitude arguments were outside of acceptable range|
|4||E_RES_DOMAIN||Resolution argument was outside of acceptable range|
|9||E_PENTAGON||Pentagon distortion was encountered which the algorithm could not handle it|
|10||E_DUPLICATE_INPUT||Duplicate input was encountered in the arguments and the algorithm could not handle it|
|13||E_MEMORY||Necessary memory allocation failed|
|14||E_MEMORY_BOUNDS||Bounds of provided memory were not large enough|
The H3 library may always add additional error messages. Error messages not recognized by the application should be treated as
Bindings translate error codes into the error handling mechanism appropriate to their language. For example, Java will convert error codes into Java Exceptions.
When possible, it is preferrable to retain the error code. When this is not possible it is fine to elide them. Language bindings should include error messages that are formatted as is usual in their language.