Checking if a handle has an associated name

I have code that goes through the open hdf5 handles and tries to print out
their names (for purposes of debugging cleanup code). I get error messages
like the one below periodically (presumably due to asking for the name of a
handle that does not have one). Is there a way to check if a handle has an
associated name? I could not find one. I can always toggle error message
printing before doing the calls, if it comes to that. And since it is
debugging code, it isn't hugely important. Thanks.

HDF5-DIAG: Error detected in HDF5 (1.8.4) thread 140179104683776:
  #000: ../../../src/H5I.c line 2106 in H5Iget_name(): can't retrieve
object name
    major: Object atom
    minor: Can't get value
  #001: ../../../src/H5Gloc.c line 202 in H5G_loc(): unable to get object
location of datatype
    major: Invalid arguments to routine
    minor: Bad value
  #002: ../../../src/H5T.c line 4744 in H5T_oloc(): not a named datatype
    major: Datatype
    minor: Unable to initialize object