tryCatch

fun <T, U, E : Throwable> T.tryCatch(catchOn: KClass<E>, body: T.() -> U): U?

Tries a function method on T, returns null if the exception was the instance of E.

Return

The result from the body function as U.

Parameters

catchOn

The exception to catch on.

body

The body function to call.


inline fun <E : Throwable, T, U> T.tryCatch(noinline body: T.() -> U): U?

Tries a function method from T, returns null if the exception was an instance of E, if not, the exception will just throw on its own.

Return

The result from the body function as U.

Parameters

body

The body function to call.