I can’t speak for the official C++ API, nevertheless from H5CPP examples I offer you this idom:
#include <h5cpp/all>
int main(){
h5::fd_t fd; // CAPI binary compatible descriptor, initialised to `H5I_UNINIT`
try { // you could optionally use C++ calls to check if the file exists, or if so, it is a valid HDF5 or just give a `try`
fd = h5::open("some_container.h5", H5F_ACC_RDWR);
} catch ( const h5::error::any& err ){
fd = h5::create("some_container.h5",H5F_ACC_TRUNC);
}
h5:ds_t ds = h5::open(fd, "dataset-name", ...);
... do your thing ...: use H5CPP templates or CAPI calls with H5CPP RAII capable descriptors
}
Here are the presentation slides, and the catch of the day: documentation on structured exceptions.
H5CPP may be downloaded from this gihub page.
steve