def getInt(path: String): Option[Int]
def getInt(path: String): Try[Int]
--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/ffa34e5d-30cb-43f4-87ea-2d68c5806e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/ffa34e5d-30cb-43f4-87ea-2d68c5806e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
private val prop:Int = configuration.getInt("mypath.to.property").getOrElse(3)
private val prop: Int = Try {
configuration.getInt("mypath.to.property")
} match {
case Success(Some(value)) => value
case _ => 3
}
What kind of exceptions are you getting that you want to handle? Once you've loaded the configuration file, that would typically only happen if your configuration is malformed. The client of your app generally shouldn't be exposed to this kind of error, since that's the developer's problem.
On Mon, Feb 13, 2017 at 6:40 PM, <ase...@gmail.com> wrote:
Many of the configuration retrieving methods have signature with a return type of Option.For e.g.
def getInt(path: String): Option[Int]I was under the impression that if Play couldn't read the config it would simply return None, but in reality it can either return Some(value), None or throw an exception! I think in the scala API it would be better much better to encode this fact in the return type itself and use a scala.util.Try
def getInt(path: String): Try[Int]Or alternatively keep the option signature but return None if there is an error. This though means the client is not exposed to the reason why the config wasn't read, so perhaps the Try is better.
--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/ffa34e5d-30cb-43f4-87ea-2d68c5806e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.