runCatching

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
inline fun <R> runCatching(block: () -> R): Result<R>

Calls the specified function block and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
inline fun <T, R> T.runCatching(block: T.() -> R): Result<R>

Calls the specified function block with this value as its receiver and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/run-catching.html