Jan. 23rd, 2012

juan_gandhi: (Default)
  def tryOr[T](message: String)(action: => T) = {
    try {
      Some(action)
    } catch {
      case e: Throwable => {
        Log.error(message, e)
        None
      }
    }
  }


using like

tryOr("Oi-vei, could not find...") { database.findUserNamed("Captain Nemo") }


Could use Either as well, I don't know.
Gradually morphing from Java.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

December 2025

S M T W T F S
  1 2 3 4 56
7 89101112 13
14 151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 15th, 2025 01:28 pm
Powered by Dreamwidth Studios