Scala safe way of converting String to Enumeration value

You can add a method to the enumeration to return an Option[Value]:

def withNameOpt(s: String): Option[Value] = values.find(_.toString == s)

Note: the existing withName method actually does precisely this, then calls getOrElse throwing the exception in the “else” case.

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.