MonadThrow extends Monad with operations for raising errors and handling them later. It makes failures explicit within effectful computations instead of leaving error handling outside the computation. section 15.3.2
trait MonadThrow[F[_]] extends Monad[F]:
extension [A](fa: F[A])
def attempt: F[Try[A]]
def handleErrorWith(h: Throwable => F[A]): F[A] =
attempt.flatMap:
case Failure(t) => h(t)
case Success(a) => unit(a)
def raiseError[A](t: Throwable): F[A]
The interface combines attempt, handleErrorWith, and raiseError: computations can expose failures, recover from them, or create them explicitly. section 15.3.2
Handling a failed computation
A Task that evaluates "asdf".toInt can be transformed with map, inspected using attempt, or recovered with handleErrorWith(_ => Task(0)). In stream processing, MonadThrow lets step interpret Pull handlers and lets Stream operations raise and handle errors. section 15.3.2
