Created
February 11, 2012 09:24
-
-
Save tototoshi/1798230 to your computer and use it in GitHub Desktop.
scalatraのparams("parameterName")がNoneとかじゃなくてNoSuchElementException返してくるのすごく納得いかない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.NoSuchElementException | |
import scala.util.control.Exception._ | |
import org.scalatra._ | |
trait SafeParams { self: ScalatraKernel => | |
def paramsSafely(key: String): Option[String] = { | |
catching(classOf[NoSuchElementException]).opt { | |
params(key) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
import java.util.NoSuchElementException | |
import scala.util.control.Exception._ | |
import org.scalatra._ | |
trait SafeParams { self: ScalatraKernel => | |
def paramsSafely(key: String): Option[String] = { | |
catching(classOf[NoSuchElementException]).opt { | |
params(key) | |
} | |
} | |
} | |
*/ | |
// params 普通にMapだった... params.get("parameterName") で Option が帰る |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment