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.
juan_gandhi: (Default)
Spent like an hour trying to figure out how to serialize to json the object I build from json (to pass around the network); then it occurred to me it's immutable. Why not keep the source, eh. Like class files, they'd be happier if they just had the source code accompanying them naturally somewhere, eh.

So there. I just store the object's own source. Neat, eh.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
18192021222324
25262728293031

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 15th, 2025 03:02 pm
Powered by Dreamwidth Studios