summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2006-11-02 08:46:39 +0000
committermihaylov <mihaylov@epfl.ch>2006-11-02 08:46:39 +0000
commit3e1e1e91bd3011ae46140f2698a578707103fe06 (patch)
tree8689732a129809698d197845233fd9e0a14eb204
parentf187d8d4737064f063cc9fbc5b036979ecc8a40f (diff)
downloadscala-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
-rw-r--r--src/library/scala/Predef.scala2
-rw-r--r--src/library/scala/compat/Platform.scala16
-rw-r--r--src/library/scala/runtime/RichException.scala27
-rwxr-xr-xsrc/library/scala/runtime/RichString.scala2
-rw-r--r--src/library/scala/testing/SUnit.scala2
-rw-r--r--test/files/run/enums.scala2
-rw-r--r--test/files/run/exceptions.scala2
7 files changed, 34 insertions, 19 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
}
diff --git a/test/files/run/enums.scala b/test/files/run/enums.scala
index 239e2944d4..1fd7dfb6c4 100644
--- a/test/files/run/enums.scala
+++ b/test/files/run/enums.scala
@@ -64,7 +64,7 @@ object Test {
} catch {
case exception: Throwable => {
Console.print(" raised exception " + exception);
- compat.Platform.printStackTrace(exception);
+ exception.printStackTrace();
}
}
Console.println;
diff --git a/test/files/run/exceptions.scala b/test/files/run/exceptions.scala
index 82740cc74d..37516737a2 100644
--- a/test/files/run/exceptions.scala
+++ b/test/files/run/exceptions.scala
@@ -33,7 +33,7 @@ object exceptions {
val value = try {
map.lookup(key)
} catch {
- case e => compat.Platform.getMessage(e)
+ case e => e.getMessage()
}
check("lookup(" + key + ")", value, "KO");
}