how to circumvent Kotlin's restriction “Type parameter is forbidden for catch parameter”
问题 I have defined the following function: inline fun <T> T.tryTo(block: T.() -> Unit): T? { try { block() } catch (ex: IllegalArgumentException) { return this } return null } The purpose is to build a chain of try-actions on an object, e.g.: val input: String = getInput(); input.tryTo /* treat as a file name and open the file */ { Desktop.getDesktop().open(File(this)) }?.tryTo /* treat as a number */ { try { doSomethingWithTheNumber(parseInt(this)) } catch (ex: NumberFormatException) { throw