diff options
author | Samuel Holland <samuel@sholland.org> | 2018-12-13 21:30:38 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-12-15 14:46:23 -0600 |
commit | dcb0e9b3e8643bc73a67c874b9add72cc0ee8f6e (patch) | |
tree | e0f720a7315a60827d19daa8ee155f09eab61586 /app/src/main/java/com/wireguard/config/InetAddresses.java | |
parent | Bump the go runtime (diff) | |
download | wireguard-android-dcb0e9b3e8643bc73a67c874b9add72cc0ee8f6e.tar.xz wireguard-android-dcb0e9b3e8643bc73a67c874b9add72cc0ee8f6e.zip |
Provide semantically meaningful exceptions for translation
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/InetAddresses.java')
-rw-r--r-- | app/src/main/java/com/wireguard/config/InetAddresses.java | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/src/main/java/com/wireguard/config/InetAddresses.java b/app/src/main/java/com/wireguard/config/InetAddresses.java index 989598da..487b136c 100644 --- a/app/src/main/java/com/wireguard/config/InetAddresses.java +++ b/app/src/main/java/com/wireguard/config/InetAddresses.java @@ -37,17 +37,18 @@ public final class InetAddresses { * @param address a string representing the IP address * @return an instance of {@link Inet4Address} or {@link Inet6Address}, as appropriate */ - public static InetAddress parse(final String address) { + public static InetAddress parse(final String address) throws ParseException { if (address.isEmpty()) - throw new IllegalArgumentException("Empty address"); + throw new ParseException(InetAddress.class, address, "Empty address"); try { return (InetAddress) PARSER_METHOD.invoke(null, address); } catch (final IllegalAccessException | InvocationTargetException e) { final Throwable cause = e.getCause(); // Re-throw parsing exceptions with the original type, as callers might try to catch // them. On the other hand, callers cannot be expected to handle reflection failures. - throw cause instanceof IllegalArgumentException ? - (IllegalArgumentException) cause : new RuntimeException(e); + if (cause instanceof IllegalArgumentException) + throw new ParseException(InetAddress.class, address, cause); + throw new RuntimeException(e); } } } |