During a PR review, I was asked to replace Sync[F].delay
with Sync[F].catchNonFatal
because an exception might be thrown.
This does work:
scala> Sync[IO].delay(throw new Exception).recover{ case t: Throwable => 42 }.unsafeRunSync
res10: Int = 42
Not being sure if that behavior was specific to IO
, I was also able to find the corresponding law saying it's actually expected, but I could not find mentions in the main cats-effect documentation about automatic handling of exceptions in the API.
Does anybody know the rationale and the expected behavior followed by cats-effect w.r.t. exceptions thrown in .delay
or .map
or .flatMap
?