Why following code
def doSomething() = \"Something\" var availableRetries: Int = 10 def process(): String = { while (true) { availableRetries -= 1 tr
import scala.annotation.tailrec import scala.util.control.Exception._ def retry[A](times: Int)(body: => A) = { @tailrec def loop(i: Int): Either[Throwable, A] = allCatch.either(body) match { case Left(_) if i > 1 => loop(i - 1) case x => x } loop(times) } retry(10) { shamelessExceptionThrower() }