nullable

inline fun <T> nullable(block: () -> T): T?

Context runner that catches and normalises all non-fatal thrown exceptions into a null value.

This is shorthand for resultOf(block).getOrNull().

// Example Usage:
val a: String? = nullable { throw Exception() } // == null
val b: String? = nullable { "Hello, World!" } // == "Hello, World!"

Return

The result of block or null if an exception was thrown.

Parameters

T

The return type of block.

block

The protected try-block which may throw an exception.