Still the newbie in Scala and I\'m now looking for a way to implement the following code on it:
@Override
public void store(InputStream source, String destin
I like the accepted solution, but suggest checking the exception is NonFatal:
// Returning T, throwing the exception on failure
@annotation.tailrec
def retry[T](n: Int)(fn: => T): T = {
Try { fn } match {
case Success(x) => x
case _ if n > 1 && NonFatal(e) => retry(n - 1)(fn)
case Failure(e) => throw e
}
}
You don't want to retry a control flow exception, and usually not for thread interrupts...