Catch exception from `H5Fis_hdf5`

Hi,

Let’s suppose I’m trying to check whether unexistent file is hdf5:

H5Fis_hdf5("unexistant_file");

Then I can see an exception:

[FD] HDF5-DIAG: Error detected in HDF5 (1.12.1) thread 0:
[FD]   #000: /home/kerim/Documents/Colada/r/HDF5/src/H5Fdeprec.c line 156 in H5Fis_hdf5(): unable to determine if file is accessible as HDF5
[FD]     major: File accessibility
[FD]     minor: Not an HDF5 file
[FD]   #001: /home/kerim/Documents/Colada/r/HDF5/src/H5VLcallback.c line 3769 in H5VL_file_specific(): file specific failed
[FD]     major: Virtual Object Layer
[FD]     minor: Can't operate on object
[FD]   #002: /home/kerim/Documents/Colada/r/HDF5/src/H5VLcallback.c line 3699 in H5VL__file_specific(): file specific failed
[FD]     major: Virtual Object Layer
[FD]     minor: Can't operate on object
[FD]   #003: /home/kerim/Documents/Colada/r/HDF5/src/H5VLnative_file.c line 384 in H5VL__native_file_specific(): error in HDF5 file check
[FD]     major: File accessibility
[FD]     minor: Unable to initialize object
[FD]   #004: /home/kerim/Documents/Colada/r/HDF5/src/H5Fint.c line 1073 in H5F__is_hdf5(): unable to open file
[FD]     major: File accessibility
[FD]     minor: Unable to initialize object
[FD]   #005: /home/kerim/Documents/Colada/r/HDF5/src/H5FD.c line 723 in H5FD_open(): open failed
[FD]     major: Virtual File Layer
[FD]     minor: Unable to initialize object
[FD]   #006: /home/kerim/Documents/Colada/r/HDF5/src/H5FDsec2.c line 352 in H5FD__sec2_open(): unable to open file: name = 'unexistant_file', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
[FD]     major: File accessibility
[FD]     minor: Unable to open file

How to catch this exception?

Oh, it seems the solution is posted here.

We are talking C here. The meaning of “catching an exception” is unclear. Muffling the error stack is not a solution but a matter of last resort.

G.

1 Like

Yes, I agree that is not a best solution.
I have to thinnk about it as I use HDF5 in my application.
Probably later I will comeback to that topic. Right now I can’t understand what I want because without mutting error stack I may get too much errors and with muting I lost information why the file is unreachable.

Thank you for clarifying about “catching exception”. Didn’t know how to formulate the question as I mostly work with C++.