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

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617 181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 19th, 2025 11:52 pm
Powered by Dreamwidth Studios