Skip to content

Commit ade2ce8

Browse files
author
Kornel Kielczewski
committed
SI-9067: Enumeration withName improvement
- Enumeration#withName in case of a failed approach to resolve the Enumeration value fails with a meaningless NoSuchElementException. Would be nice to know what exactly is not found
1 parent 409b280 commit ade2ce8

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)