Skip to content

Commit e7025c4

Browse files
committed
mustBe* throwascaller
1 parent d721fc6 commit e7025c4

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

+stdlib/+fileio/private/mustBeFile.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function mustBeFile(a)
33
a string {mustBeNonzeroLengthText}
44
end
55

6-
assert(all(isfile(stdlib.fileio.expanduser(a)), 'all'), "%s is not a file", a)
6+
if ~all(isfile(stdlib.fileio.expanduser(a)), 'all')
7+
throwAsCaller(MException('MATLAB:validators:mustBeFile', a + " is not a file"))
8+
end
79

810
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function mustBeNonzeroLengthText(a)
22

33
if ~((ischar(a) || isstring(a) || iscellstr(a)) && all(strlength(a) > 0, 'all'))
4-
error("MATLAB:validators:mustBeNonzeroLengthText", "text must have non-zero length")
4+
throwAsCaller(MException("MATLAB:validators:mustBeNonzeroLengthText", "text must have non-zero length"))
55
end
66

7-
end
7+
end

+stdlib/+hdf5nc/private/mustBeFile.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function mustBeFile(a)
33
a string {mustBeNonzeroLengthText}
44
end
55

6-
assert(all(isfile(stdlib.fileio.expanduser(a)), 'all'), "%s is not a file", a)
6+
if ~all(isfile(stdlib.fileio.expanduser(a)), 'all')
7+
throwAsCaller(MException('MATLAB:validators:mustBeFile', a + " is not a file"))
8+
end
79

810
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function mustBeNonzeroLengthText(a)
22

33
if ~((ischar(a) || isstring(a) || iscellstr(a)) && all(strlength(a) > 0, 'all'))
4-
error("MATLAB:validators:mustBeNonzeroLengthText", "text must have non-zero length")
4+
throwAsCaller(MException("MATLAB:validators:mustBeNonzeroLengthText", "text must have non-zero length"))
55
end
66

7-
end
7+
end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function mustBeScalarOrEmpty(x)
22

3-
assert(isempty(x) || isscalar(x), "must be scalar or empty")
3+
if ~(isempty(x) || isscalar(x))
4+
throwAsCaller(MException('MATLAB:validators:mustBeScalarOrEmpty', "must be scalar or empty"))
5+
end
46

57
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function mustBeScalarOrEmpty(x)
2-
% for Matlab < R2020b
3-
4-
assert(isempty(x) || isscalar(x), "must be scalar or empty")
2+
if ~(isempty(x) || isscalar(x))
3+
throwAsCaller(MException('MATLAB:validators:mustBeScalarOrEmpty', "must be scalar or empty"))
4+
end
55

66
end

0 commit comments

Comments
 (0)