Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Created January 21, 2014 21:18
Show Gist options
  • Save manjuraj/8548582 to your computer and use it in GitHub Desktop.
Save manjuraj/8548582 to your computer and use it in GitHub Desktop.
TryHarder - Try with finally
import scala.util.Try
implicit class TryHarder[T](t:Try[T]) {
def harder(f: => Unit) = {f; t}
}
Try(1/0).harder(println("finally")) // prints 'finally'
Try(try { ??? } finally { 1 / 0 }).harder(println("finally finally")) // prints 'finally finally'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment