Skip to content

Commit 61caba4

Browse files
committed
Merge pull request scala#4229 from Kornel/feature/SI-9067-enumeration-with-name-improvement
SI-9067: Enumeration withName improvement
2 parents 3fafbc2 + ade2ce8 commit 61caba4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/library/scala/Enumeration.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ abstract class Enumeration (initial: Int) extends Serializable {
121121
* @throws NoSuchElementException if no `Value` with a matching
122122
* name is in this `Enumeration`
123123
*/
124-
final def withName(s: String): Value = values.find(_.toString == s).get
124+
final def withName(s: String): Value = values.find(_.toString == s).getOrElse(
125+
throw new NoSuchElementException(s"No value found for '$s'"))
125126

126127
/** Creates a fresh value, part of this enumeration. */
127128
protected final def Value: Value = Value(nextId)

0 commit comments

Comments
 (0)