You can in general make your reference to the HDF5 file exception safe by following the standard RAII (Resource Acquisition is Initialization) paradigm. This will not, however, protect you from segfaults which are an operating system generated interrupt to your program, unless you catch the interrupt and close the file.
For the simpler case of exception safety, this can be achieved through a couple of best practices. First, acquire the resource during the call to the object constructor. Write a copy constructor and overload the assignment operator to correctly transfer ownership of the file handle rather than simply holding the pointer from two places. Finally, write a destructor for the object that correctly closes the file handle.