From 5c1e84703afd52714134cbd97475303a5d69a3c4 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 1 Feb 2019 22:07:31 +0800 Subject: [PATCH] Refine InterfaceNotFoundException --- .../src/main/java/be/mygod/vpnhotspot/net/Routing.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index bb90573d..37ac5d59 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -87,12 +87,16 @@ class Routing(val caller: Any, val downstream: String, ownerAddress: InterfaceAd None, Simple, Netd } - class InterfaceNotFoundException : SocketException() { + class InterfaceNotFoundException(override val cause: Throwable) : SocketException() { override val message: String get() = app.getString(R.string.exception_interface_not_found) } - val hostAddress = ownerAddress ?: NetworkInterface.getByName(downstream)?.interfaceAddresses?.asSequence() - ?.singleOrNull { it.address is Inet4Address } ?: throw InterfaceNotFoundException() + val hostAddress = try { + ownerAddress ?: NetworkInterface.getByName(downstream)!!.interfaceAddresses!! + .asSequence().single { it.address is Inet4Address } + } catch (e: Exception) { + throw InterfaceNotFoundException(e) + } val hostSubnet = "${hostAddress.address.hostAddress}/${hostAddress.networkPrefixLength}" private val transaction = RootSession.beginTransaction()