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.
Written by Erik Allik
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#