Test group existence in hdf5/c++
<p>I am opening an existing HDF5 file for appending data; I want to assure that group called <code>/A</code> exists for subsequent access. I am looking for an easy way to either create <code>/A</code> conditionally (create and return new group if not existing, or return the existing group). One way is to test for <code>/A</code> existence. How can I do it efficiently? </p>

<p>According to the API docs, I can do something like this:</p>

<pre><code>H5::H5File h5file(filename,H5F_ACC_RDWR);
H5::H5Group grp;
try{
   grp=h5file.openGroup("A");
} catch(H5::Exception&amp; e){
   /* group does not exists, create it */
   grp=h5file.createGroup("A");
}
</code></pre>

<p>but the obvious ugliness comes from the fact that exception is used to communicate information which is not exceptional at all.</p>

<p>There is <a href="https://www.hdfgroup.org/HDF5/doc/cpplus_RM/class_h5_1_1_common_f_g.html#a9832f8d8c05590650b1e8d48992622c1" rel="noreferrer">H5::CommonFG::getObjinfo</a>, which seems to wrap <a href="https://www.hdfgroup.org/HDF5/doc/RM/RM_H5G.html#Group-GetObjinfo" rel="noreferrer">H5Gget_objinfo</a> in such way that false (nonexistent) return value of the C routine throws an exception; so again the same problem.</p>

<p>Is it clean to recourse to the C API in this case, or is there some function directly designed to test existence in the C++ API which I am overlooking?</p>