JoakimForslund
02/24/2020, 12:25 PMvar result: T? = null
try {
println("FFFFFFFfffff - 2")
result = httpClient?.request(httpRequestBuilder)
} catch (e: Exception) {
println("FFFFFFFfffff - 3: ${e.cause} -> ${e.message}")
throw e.cause!!
} finally {
println("FFFFFFFfffff - 4: ${result}")
return result
}
Essentially the result ends up with null, which is not weird because it is initially set as such, however the httpClient?.request does not throw an error and the result is still null
The httpClient is initialized, and the engine is also initialized. I'm confused as to whyribesg
02/24/2020, 12:56 PMfinally
blockribesg
02/24/2020, 12:57 PMfinally
block is executed all the time, even after the catch
block has been run. So here you’re both throwing an error THEN returning? I don’t know. It looks weird to meJoakimForslund
02/24/2020, 12:58 PMribesg
02/24/2020, 12:59 PMJoakimForslund
02/24/2020, 12:59 PMribesg
02/24/2020, 12:59 PMribesg
02/24/2020, 1:00 PMribesg
02/24/2020, 1:00 PMribesg
02/24/2020, 1:00 PMtry-catch
JoakimForslund
02/24/2020, 1:01 PMribesg
02/24/2020, 1:02 PMfinally
when you want to run code after a try-catch even if it catches, for cleanup or potentially logging, but you should never need to returnJoakimForslund
02/24/2020, 1:03 PMribesg
02/24/2020, 1:03 PMprintln(httpClient)
before result = …
JoakimForslund
02/24/2020, 1:04 PMribesg
02/24/2020, 1:04 PMThrowable
instead of Exception
maybeJoakimForslund
02/24/2020, 1:05 PMribesg
02/24/2020, 1:05 PM.request(…)
returns null
but that would be weirdribesg
02/24/2020, 1:05 PMJoakimForslund
02/24/2020, 1:07 PMrequest(..)
is for all I can see returning null. This with the latest KotlinxSerializer
which does specify that you no longer need to register specific serializersJoakimForslund
02/24/2020, 1:07 PMJoakimForslund
02/24/2020, 1:11 PMJoakimForslund
02/24/2020, 1:11 PMLeon K
02/24/2020, 1:34 PMval result: T? = httpClient?.use { client ->
try {
client.request(httpRequestBuilder)
} catch(e: Throwable) {
println(...)
throw e.cause!! // <- this is weird too, but idk
}
}
there seems no need to have result be uninitialized first, or to have the finally partLeon K
02/24/2020, 1:35 PMThrowable
as that will contain a lot of things you most likely don't want to catch there. Even if it is just for intermediate logging,... do that logging higher upJoakimForslund
02/24/2020, 1:35 PMLeon K
02/24/2020, 1:37 PM.use
if not