diff options
author | mihaylov <mihaylov@epfl.ch> | 2006-11-02 08:46:39 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2006-11-02 08:46:39 +0000 |
commit | 3e1e1e91bd3011ae46140f2698a578707103fe06 (patch) | |
tree | 8689732a129809698d197845233fd9e0a14eb204 /src | |
parent | f187d8d4737064f063cc9fbc5b036979ecc8a40f (diff) | |
download | scala-3e1e1e91bd3011ae46140f2698a578707103fe06.tar.gz scala-3e1e1e91bd3011ae46140f2698a578707103fe06.tar.bz2 scala-3e1e1e91bd3011ae46140f2698a578707103fe06.zip |
- added runtime.RichException with a getStackTr...
- added runtime.RichException with a getStackTraceString method (the
- .NET version will be more extensive) added a split(c: Char) method to
- RichString
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/Predef.scala | 2 | ||||
-rw-r--r-- | src/library/scala/compat/Platform.scala | 16 | ||||
-rw-r--r-- | src/library/scala/runtime/RichException.scala | 27 | ||||
-rwxr-xr-x | src/library/scala/runtime/RichString.scala | 2 | ||||
-rw-r--r-- | src/library/scala/testing/SUnit.scala | 2 |
5 files changed, 32 insertions, 17 deletions
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 1673ba90a1..532b1255ea 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -121,6 +121,8 @@ object Predef { implicit def stringWrapper(x: String) = new runtime.RichString(x) + implicit def exceptionWareppr(exc: Throwable) = new runtime.RichException(exc) + implicit def int2ordered(x: int): Ordered[int] = new Ordered[int] with Proxy { def self: Any = x diff --git a/src/library/scala/compat/Platform.scala b/src/library/scala/compat/Platform.scala index 43c5c22498..85eecb825a 100644 --- a/src/library/scala/compat/Platform.scala +++ b/src/library/scala/compat/Platform.scala @@ -32,24 +32,8 @@ object Platform { def getElementClass(obj: AnyRef) = obj.getClass().getComponentType(); def getClassForName(name: String): Class = java.lang.Class.forName(name); - def printStackTrace(exc: java.lang.Throwable) = exc.printStackTrace(); - def getMessage(exc: java.lang.Throwable) = exc.getMessage(); - val EOL = System.getProperty("line.separator", "\n") - def getStackTrace(exc: java.lang.Throwable): String = { - val s = new StringBuilder() - for (val trElem <- exc.getStackTrace()) { - s.append(trElem.toString()) - s.append(EOL) - } - s.toString() - } - - def split(str: String, separator: Char): Array[String] = { - str.split(separator.toString()); - } - def currentTime: Long = System.currentTimeMillis() def collectGarbage: Unit = System.gc() diff --git a/src/library/scala/runtime/RichException.scala b/src/library/scala/runtime/RichException.scala new file mode 100644 index 0000000000..a3d430237c --- /dev/null +++ b/src/library/scala/runtime/RichException.scala @@ -0,0 +1,27 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: RichString.scala 9112 2006-11-01 16:58:23Z michelou $ + + +package scala.runtime + +import compat.Platform.EOL + +final class RichException(exc: Throwable) { + + def getStackTraceString: String = { + val s = new StringBuilder() + for (val trElem <- exc.getStackTrace()) { + s.append(trElem.toString()) + s.append(EOL) + } + s.toString() + } + +} diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala index d4010bd7ba..9e8142ab9c 100755 --- a/src/library/scala/runtime/RichString.scala +++ b/src/library/scala/runtime/RichString.scala @@ -118,6 +118,8 @@ final class RichString(s: String) { */ def stripMargin: String = stripMargin('|') + def split(separator: Char): Array[String] = s.split(separator.toString()) + def toByte: Byte = java.lang.Byte.parseByte(s) def toShort: Short = java.lang.Short.parseShort(s) def toInt: Int = java.lang.Integer.parseInt(s) diff --git a/src/library/scala/testing/SUnit.scala b/src/library/scala/testing/SUnit.scala index fe1f77e170..dfacdf48a0 100644 --- a/src/library/scala/testing/SUnit.scala +++ b/src/library/scala/testing/SUnit.scala @@ -85,7 +85,7 @@ object SUnit { override def toString() = failedTest.toString() + " failed due to " + thrownException.toString() - def trace(): String = compat.Platform.getStackTrace(thrownException) + def trace(): String = thrownException.getStackTraceString } |