Just for completeness, as the other solutions are quite good:
You also could use the functional error handling, that is part of Scala sine 2.10.
The Try will wrap the result and you will either get an Success[ ScalaType.Value ] or an Failure[ Error ].
import scala.util.Try
def byNameFunctional(name: String) = Try( ScaleType.withName(name) )
Examples:
scala> byNameFunctional("nominal")
res2: scala.util.Try[ScaleType.Value] = Success(nominal)
scala> byNameFunctional("blah")
res3: scala.util.Try[ScaleType.Value] = Failure(java.util.NoSuchElementException: None.get)
A nice addition is that you can match and map over the results, and the error is kept in the result:
scala> byNameFunctional("nominal") map (_.toString + "!!!")
res5: scala.util.Try[String] = Success(nominal!!!)
scala> byNameFunctional("nominal123") map (_.toString + "!!!")
res6: scala.util.Try[String] = Failure(java.util.NoSuchElementException: None.get)