Why following code
def doSomething() = \"Something\"
var availableRetries: Int = 10
def process(): String = {
while (true) {
availableRetries -= 1
tr
Based on senia, elbowich and dave's solutions I used following:
@annotation.tailrec
def retry[T](availableRetries: Int)(action: => T): T = {
try {
return action
} catch {
case e: Exception if (availableRetries > 0) => { }
}
retry(availableRetries - 1)(action)
}
Which can be then used as elbowich and dave's solutions:
retry(3) {
// some code
}