Skip to content

Commit 0eda9d4

Browse files
committed
h5variables: return empty if group doesn't exist
1 parent b940542 commit 0eda9d4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

+stdlib/+hdf5nc/h5variables.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222

2323
names = string.empty;
2424

25-
finf = h5info(file, group);
25+
try
26+
finf = h5info(file, group);
27+
catch e
28+
if e.identifier == "MATLAB:imagesci:h5info:unableToFind"
29+
return
30+
end
31+
rethrow(e)
32+
end
2633

2734
ds = finf.Datasets;
2835

+stdlib/+test/TestHDF5.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ function test_get_variables(tc)
9191
tc.verifyEqual(sort(v), ["x", "y"])
9292

9393
% traversal
94-
v = h5variables(basic, "/j");
95-
tc.verifyEmpty(v)
94+
tc.verifyEmpty( h5variables(basic, "/j") )
9695

97-
v = h5variables(basic, "/j/a");
98-
tc.verifyEqual(v, "b")
96+
% non-existant group
97+
tc.verifyEmpty( h5variables(basic, "/nothere") )
98+
99+
tc.verifyEqual( h5variables(basic, "/j/a") , "b")
99100

100101
end
101102

0 commit comments

Comments
 (0)