This is basically to wrap java factory methods which throw exceptions if the item can\'t be created based on the inputs. I\'m looking for something in the base library like:
As of scala 2.10, you can run your code (e.g. factory method) in a scala.util.Try and then convert it with toOption
:
import scala.util.Try
Try("foo".toInt).toOption // None
Try("7".toInt).toOption // Some(7)
Or translated to your original example:
val id: Option[UUID] = Try(UUID.fromString("this will produce None")).toOption