I am using Spring WebClient in a Kotlin project , for example:
data class DTO(val name: String)
@Component
class Runner: ApplicationRunner
{
override fun run(args: ApplicationArguments?)
{
try
{
val dto = get<DTO>()
}
catch (e: Exception)
{
println("ERROR, all exceptions should have been caught in 'get' ")
}
}
}
inline private fun<reified TResult: Any> get(): TResult?
{
var result: TResult? = null
try
{
result = WebClient.create("https://maps.googleapis.com/maps/api/nonexisting")
.get()
.retrieve()
.bodyToMono<TResult>()
.block()
}
catch (e: Exception)
{
println("WORKS AS EXPECTED!!")
}
return result
}
The client will throw an exception because the API will return 404. However, the exception is not caught where it should be, namely in the body of the function get, but it extends to the external exception handler.
It is interesting to note that this only happens if an exception is thrown WebClient. If I replaced the code in the sentence with a trysimple one throw Exception("error"), the exception will be caught where it should be.
Similarly, when I change the signature getto a non-generic one inline private fun get(): DTO? , the problem also disappears.
, try-catch, Kotlin. , , WebClient, , Spring. , .
, . , , . , , :

Spring Boot 2.0.0.M6, M5.
, Spring, Kotlin. , , , , , -, , .