Checking if file exists without having error message

I am trying to write data into a HDF5 file. And I want to check if the file already exists before I write. So I checked the status of H5Fopen.

file_id = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT);
if (file_id < 0 ) {…}

But I always got the error message from function H5Fopen saying “unable to open to file”. Is there any way to check without having such message?

You could wrap your call to H5Fopen() in H5E_BEGIN_TRY / H5E_END_TRY.

Quincey

Thank you! It works.