From ade2ce8623e0d923d922809f2b705732918281bc Mon Sep 17 00:00:00 2001 From: Kornel Kielczewski Date: Wed, 31 Dec 2014 15:34:47 +0100 Subject: 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 --- src/library/scala/Enumeration.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/library') diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index e11d1b35d7..c4aa511cd7 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -121,7 +121,8 @@ abstract class Enumeration (initial: Int) extends Serializable { * @throws NoSuchElementException if no `Value` with a matching * name is in this `Enumeration` */ - final def withName(s: String): Value = values.find(_.toString == s).get + final def withName(s: String): Value = values.find(_.toString == s).getOrElse( + throw new NoSuchElementException(s"No value found for '$s'")) /** Creates a fresh value, part of this enumeration. */ protected final def Value: Value = Value(nextId) -- cgit v1.2.3