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

October 2025

S M T W T F S
    1 23 4
5 678 9 1011
12 13 1415 161718
1920 2122 23 2425
26 2728 293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 31st, 2025 05:23 am
Powered by Dreamwidth Studios