Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 34a55c4

Browse filesBrowse files
committed
More explicit exception types.
1 parent 9371c5b commit 34a55c4
Copy full SHA for 34a55c4

File tree

1 file changed

+18
-18
lines changed
Filter options

1 file changed

+18
-18
lines changed

‎com/arrayfire/Array.java

Copy file name to clipboardExpand all lines: com/arrayfire/Array.java
+18-18Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private Type(int type) {
1616
this.type = type;
1717
}
1818

19-
public static Type fromInt(int type) throws Exception {
19+
public static Type fromInt(int type) throws IllegalArgumentException {
2020
switch (type) {
2121
case 0:
2222
return Type.Float;
@@ -31,7 +31,7 @@ public static Type fromInt(int type) throws Exception {
3131
case 5:
3232
return Type.Int;
3333
default:
34-
throw new Exception("Unknown type.");
34+
throw new IllegalArgumentException("Unknown type.");
3535
}
3636
}
3737

@@ -96,7 +96,7 @@ public Array(int[] dims, int type) throws Exception {
9696
set(createEmptyArray(adims, type));
9797
}
9898

99-
public Array(int[] dims, float[] elems) throws Exception {
99+
public Array(int[] dims, float[] elems) throws IllegalArgumentException {
100100
int[] adims = Array.dim4(dims);
101101

102102
int total_size = 1;
@@ -105,17 +105,17 @@ public Array(int[] dims, float[] elems) throws Exception {
105105
}
106106

107107
if (elems == null) {
108-
throw new Exception("Null elems object provided");
108+
throw new IllegalArgumentException("Null elems object provided");
109109
}
110110

111111
if (elems.length > total_size || elems.length < total_size) {
112-
throw new Exception("Mismatching dims and array size");
112+
throw new IllegalArgumentException("Mismatching dims and array size");
113113
}
114114

115115
set(createArrayFromFloat(adims, elems));
116116
}
117117

118-
public Array(int[] dims, double[] elems) throws Exception {
118+
public Array(int[] dims, double[] elems) throws IllegalArgumentException {
119119
int[] adims = Array.dim4(dims);
120120

121121
int total_size = 1;
@@ -124,29 +124,29 @@ public Array(int[] dims, double[] elems) throws Exception {
124124
}
125125

126126
if (elems == null) {
127-
throw new Exception("Null elems object provided");
127+
throw new IllegalArgumentException("Null elems object provided");
128128
}
129129

130130
if (elems.length > total_size || elems.length < total_size) {
131-
throw new Exception("Mismatching dims and array size");
131+
throw new IllegalArgumentException("Mismatching dims and array size");
132132
}
133133

134134
set(createArrayFromDouble(adims, elems));
135135
}
136136

137-
public Array(int[] dims, int[] elems) throws Exception {
137+
public Array(int[] dims, int[] elems) throws IllegalArgumentException {
138138
int[] adims = Array.dim4(dims);
139139

140140
int total_size = 1;
141141
for (int dim : adims) {
142142
total_size *= dim;
143143
}
144144
if (elems == null) {
145-
throw new Exception("Null elems object provided");
145+
throw new IllegalArgumentException("Null elems object provided");
146146
}
147147

148148
if (elems.length > total_size || elems.length < total_size) {
149-
throw new Exception("Mismatching dims and array size");
149+
throw new IllegalArgumentException("Mismatching dims and array size");
150150
}
151151

152152
set(createArrayFromInt(adims, elems));
@@ -171,7 +171,7 @@ public Array(int[] dims, FloatComplex[] elems) throws Exception {
171171
set(createArrayFromFloatComplex(adims, elems));
172172
}
173173

174-
public Array(int[] dims, DoubleComplex[] elems) throws Exception {
174+
public Array(int[] dims, DoubleComplex[] elems) throws IllegalArgumentException {
175175
int[] adims = Array.dim4(dims);
176176

177177
int total_size = 1;
@@ -180,11 +180,11 @@ public Array(int[] dims, DoubleComplex[] elems) throws Exception {
180180
}
181181

182182
if (elems == null) {
183-
throw new Exception("Null elems object provided");
183+
throw new IllegalArgumentException("Null elems object provided");
184184
}
185185

186186
if (elems.length > total_size || elems.length < total_size) {
187-
throw new Exception("Mismatching dims and array size");
187+
throw new IllegalArgumentException("Mismatching dims and array size");
188188
}
189189

190190
set(createArrayFromDoubleComplex(adims, elems));
@@ -204,12 +204,12 @@ public Array.Type type() throws Exception {
204204
return Array.Type.fromInt(getType(ref));
205205
}
206206

207-
protected static int[] dim4(int[] dims) throws Exception {
207+
protected static int[] dim4(int[] dims) throws IllegalArgumentException {
208208

209209
if (dims == null) {
210-
throw new Exception("Null dimensions object provided");
210+
throw new IllegalArgumentException("Null dimensions object provided");
211211
} else if (dims.length > 4) {
212-
throw new Exception("ArrayFire supports up to 4 dimensions only");
212+
throw new IllegalArgumentException("ArrayFire supports up to 4 dimensions only");
213213
}
214214

215215
int[] adims = new int[] { 1, 1, 1, 1 };
@@ -225,7 +225,7 @@ protected void assertType(Array.Type ty) throws Exception {
225225
String str = "Type mismatch: ";
226226
str = str + "Requested " + ty;
227227
str = str + ". Found " + myType;
228-
throw new Exception(str);
228+
throw new IllegalArgumentException(str);
229229
}
230230
return;
231231
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.