recover Exception
inline fun <E : Throwable, R, T : R> CatchingResult<T>.recoverException(transform: (E) -> R): CatchingResult<Any?>(source)
如果异常为 E,对 T 进行 transform,返回新的 CatchingResult。
注意不要使用尖括号声明类型 E,如 recoverException<IOException>()。 请使用 lambda 参数来声明异常类型,编译器会推断全部三个泛型。
示例:
trace.catching { error("Error") }
.recoverException { e: IllegalStateException -> e.message }Content copied to clipboard