diff options
author | Paul Phillips <paulp@improving.org> | 2010-10-12 22:16:51 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-10-12 22:16:51 +0000 |
commit | 46d5e73c11bccd0e892429e4c3f2ac1a02cea2a9 (patch) | |
tree | 942450274b554196ca81a8fa4538e16ef297bbc8 | |
parent | 38d450043069c9c2607393135f110bcf215790ca (diff) | |
download | scala-46d5e73c11bccd0e892429e4c3f2ac1a02cea2a9.tar.gz scala-46d5e73c11bccd0e892429e4c3f2ac1a02cea2a9.tar.bz2 scala-46d5e73c11bccd0e892429e4c3f2ac1a02cea2a9.zip |
Two improvements (or so I claim) to MatchErrors.
toString when constructing the exception: it need not be called
until/unless it is printed, which it may never be. 2) Include the name
of the class which triggered it. Don't tell me you haven't wanted that
as many times as I have.
(Sidebar on commit message semantics: I assume nobody interprets "no
review" to mean anything like "unreviewable decision!" It only means I'm
pretty sure the code does what I intended. The floor is always open.)
That said, no review.
-rw-r--r-- | src/library/scala/MatchError.scala | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/library/scala/MatchError.scala b/src/library/scala/MatchError.scala index 31783da4d3..5f0f7e2dfc 100644 --- a/src/library/scala/MatchError.scala +++ b/src/library/scala/MatchError.scala @@ -19,7 +19,13 @@ package scala * @version 1.1, 05/03/2004 * @since 2.0 */ -final class MatchError(msg: String) extends RuntimeException(msg) { - def this(obj: Any) = - this(if (null != obj) obj.toString() else "null") +final class MatchError(obj: Any) extends RuntimeException { + /** There's no reason we need to call toString eagerly, + * so defer it until getMessage is called. + */ + private lazy val objString = + if (obj == null) "null" + else obj.toString() + " (of class " + obj.asInstanceOf[AnyRef].getClass.getName + ")" + + override def getMessage() = objString } |