Last Updated: February 25, 2016
·
522
· eallik

Emulate Python's try-else semantics in Scala

object Done extends Exception

try {
  doSomethingRisky()
  throw Done
} catch {
  case e: Exception =>
    handleError(e)
  case Done =>
    println("OK")
} finally {
  wrapUp()
}

Note that this is not the same as putting the done block after the try-catch-finally block—the done block will be executed before the finally block.