runCatching and Result<T>
Use runCatching to wrap exceptions in Result and process them functionally.
Result<T> in a Nutshell
Result<T> is Kotlin's wrapper for an operation outcome: either a success with a value of type T or a failure with a Throwable.
runCatching Basics
runCatching { ... } runs the block and wraps the outcome in a Result.
fun main() {
val good = runCatching { 10 / 2 }
val bad = runCatching { 10 / 0 }
println("good isSuccess = ${good.isSuccess}")
println("bad isFailure = ${bad.isFailure}")
}