diff options
author | Kornel Kielczewski <kornel.kielczewski@allegrogroup.com> | 2014-12-31 15:34:47 +0100 |
---|---|---|
committer | Kornel Kielczewski <kornel.kielczewski@allegrogroup.com> | 2015-01-05 21:22:44 +0100 |
commit | ade2ce8623e0d923d922809f2b705732918281bc (patch) | |
tree | 8b7fae39c32d33b105c18c2bd49b7c25ec5f34e3 | |
parent | 409b2805e0f6263b4e64197bc09ae58202d45f5e (diff) | |
download | scala-ade2ce8623e0d923d922809f2b705732918281bc.tar.gz scala-ade2ce8623e0d923d922809f2b705732918281bc.tar.bz2 scala-ade2ce8623e0d923d922809f2b705732918281bc.zip |
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
-rw-r--r-- | src/library/scala/Enumeration.scala | 3 |
1 files changed, 2 insertions, 1 deletions
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) |