catch

abstract fun <A> catch(f: STM.() -> A, onError: STM.(Throwable) -> A): A(source)

Run f and handle any exception thrown with onError.

import arrow.fx.stm.atomically

suspend fun main() {
//sampleStart
val result = atomically {
catch({ throw Throwable() }) { e -> "caught" }
}
//sampleEnd
println("Result $result")
}