Skip to content

Commit 1b9203e

Browse files
committed
No checked Exceptions when building a CoreLabel from items
Throw UnsupportedOperationException immediately for a type which can't be converted in UnsupportedOperationException when building a CoreLabel from items
1 parent e7a7657 commit 1b9203e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/edu/stanford/nlp/ling/AnnotationLookup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static Class<?> getValueType(Class<? extends CoreAnnotation<?>> key) {
156156
try {
157157
type = key.newInstance().getType();
158158
} catch (Exception e) {
159-
throw new RuntimeException("Unexpected failure to instantiate - is your key class fancy?", e);
159+
throw new UnsupportedOperationException("Unexpected failure to instantiate - is your key class fancy?", e);
160160
}
161161
valueCache.put((Class)key, type);
162162
}

src/edu/stanford/nlp/ling/CoreLabel.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ private void initFromStrings(String[] keys, String[] values) {
198198
} else if(valueClass == Long.class) {
199199
this.set(coreKeyClass, Long.parseLong(values[i]));
200200
} else {
201-
throw new RuntimeException("Can't handle " + valueClass);
201+
throw new UnsupportedOperationException("CORE: CoreLabel.initFromStrings: " +
202+
"Can't handle " + valueClass + " (key " + key + ")");
202203
}
203-
} catch (Exception e) {
204+
} catch (NumberFormatException e) {
204205
// unexpected value type
205206
throw new UnsupportedOperationException("CORE: CoreLabel.initFromStrings: "
206207
+ "Bad type for " + key
@@ -246,9 +247,10 @@ private void initFromStrings(Class[] keys, String[] values) {
246247
} else if (valueClass == Long.class) {
247248
this.set(coreKeyClass, Long.parseLong(values[i]));
248249
} else {
249-
throw new RuntimeException("Can't handle " + valueClass);
250+
throw new UnsupportedOperationException("CORE: CoreLabel.initFromStrings: " +
251+
"Can't handle " + valueClass + " (key " + coreKeyClass + ")");
250252
}
251-
} catch (Exception e) {
253+
} catch (NumberFormatException e) {
252254
// unexpected value type
253255
throw new UnsupportedOperationException("CORE: CoreLabel.initFromStrings: "
254256
+ "Bad type for " + coreKeyClass.getSimpleName()

0 commit comments

Comments
 (0)