Skip to content

Commit 4cd033b

Browse files
authored
Merge pull request #97 from maxmind/greg/improve-exception
Improve exception message and include cause
2 parents eb3b3b3 + 0f268b1 commit 4cd033b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
2.1.0
5+
------------------
6+
7+
* Messages for `DeserializationException` have been improved and the
8+
cause is included, if any.
9+
410
2.0.0 (2020-10-13)
511
------------------
612

src/main/java/com/maxmind/db/Decoder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private <T, V> List<V> decodeArray(
294294
try {
295295
constructor = cls.getConstructor(Integer.TYPE);
296296
} catch (NoSuchMethodException e) {
297-
throw new DeserializationException("No constructor found for the List: " + e);
297+
throw new DeserializationException("No constructor found for the List: " + e.getMessage(), e);
298298
}
299299
Object[] parameters = {size};
300300
try {
@@ -304,7 +304,7 @@ private <T, V> List<V> decodeArray(
304304
} catch (InstantiationException |
305305
IllegalAccessException |
306306
InvocationTargetException e) {
307-
throw new DeserializationException("Error creating list: " + e);
307+
throw new DeserializationException("Error creating list: " + e.getMessage(), e);
308308
}
309309
}
310310

@@ -355,7 +355,7 @@ private <T, V> Map<String, V> decodeMapIntoMap(
355355
try {
356356
constructor = cls.getConstructor(Integer.TYPE);
357357
} catch (NoSuchMethodException e) {
358-
throw new DeserializationException("No constructor found for the Map: " + e);
358+
throw new DeserializationException("No constructor found for the Map: " + e.getMessage(), e);
359359
}
360360
Object[] parameters = {size};
361361
try {
@@ -365,7 +365,7 @@ private <T, V> Map<String, V> decodeMapIntoMap(
365365
} catch (InstantiationException |
366366
IllegalAccessException |
367367
InvocationTargetException e) {
368-
throw new DeserializationException("Error creating map: " + e);
368+
throw new DeserializationException("Error creating map: " + e.getMessage(), e);
369369
}
370370
}
371371

@@ -437,7 +437,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
437437
} catch (InstantiationException |
438438
IllegalAccessException |
439439
InvocationTargetException e) {
440-
throw new DeserializationException("Error creating object: " + e);
440+
throw new DeserializationException("Error creating object: " + e.getMessage(), e);
441441
}
442442
}
443443

src/main/java/com/maxmind/db/DeserializationException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ public class DeserializationException extends RuntimeException {
1313
DeserializationException(String message) {
1414
super(message);
1515
}
16+
DeserializationException(String message, Throwable cause) {
17+
super(message, cause);
18+
}
1619
}

0 commit comments

Comments
 (0)