nullable

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

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

// 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.


inline fun <In, Out> In.nullable(block: In.() -> Out): Out?

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

// Example Usage:
val a: String? = 0.nullable { throw Exception() } // == null
val b: String? = 0.nullable { toString() } // == "0"

Return

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

Parameters

In

The receiver type of block.

Out

The return type of block.

block

The protected try-block which may throw an exception.