summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-12-02 04:59:19 +0000
committerPaul Phillips <paulp@improving.org>2009-12-02 04:59:19 +0000
commit75d02a1a5278b49487cef7669c998d4b052bbb2d (patch)
tree2a8ef5d6c8a06704ccf50445d8345293040e67d3 /src
parentf54e15370e7e90aa303103c8d3aadb22d0164b10 (diff)
downloadscala-75d02a1a5278b49487cef7669c998d4b052bbb2d.tar.gz
scala-75d02a1a5278b49487cef7669c998d4b052bbb2d.tar.bz2
scala-75d02a1a5278b49487cef7669c998d4b052bbb2d.zip
Making the Try/Catch/Finally in ScalaRunTime to...
Making the Try/Catch/Finally in ScalaRunTime to do what it looks like they were intended to do. (This code looks like it dates from the Nixon administration, so deleting it might be better.)
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/runtime/ExceptionHandling.java26
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala50
2 files changed, 26 insertions, 50 deletions
diff --git a/src/library/scala/runtime/ExceptionHandling.java b/src/library/scala/runtime/ExceptionHandling.java
deleted file mode 100644
index 73a6647ed2..0000000000
--- a/src/library/scala/runtime/ExceptionHandling.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime;
-
-
-public abstract class ExceptionHandling {
-
- public static Throwable tryCatch(Runnable runnable) {
- try {
- runnable.run();
- return null;
- } catch (Throwable exception) {
- return exception;
- }
- }
-
-}
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 015d05d62e..c193796033 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -15,6 +15,7 @@ import scala.reflect.ClassManifest
import scala.collection.Seq
import scala.collection.mutable._
import scala.collection.immutable.{ List, Stream, Nil, :: }
+import scala.util.control.ControlException
/* The object <code>ScalaRunTime</code> provides ...
*/
@@ -62,32 +63,33 @@ object ScalaRunTime {
def checkInitialized[T <: AnyRef](x: T): T =
if (x == null) throw new UninitializedError else x
- abstract class Try[a] {
- def Catch[b >: a](handler: PartialFunction[Throwable, b]): b
- def Finally(handler: Unit): a
+ abstract class Try[+A] {
+ def Catch[B >: A](handler: PartialFunction[Throwable, B]): B
+ def Finally(fin: => Unit): A
}
- def Try[a](block: => a): Try[a] = new Try[a] with Runnable {
- var result: a = _
- var exception: Throwable = ExceptionHandling.tryCatch(this)
-
- def run(): Unit = result = block
-
- def Catch[b >: a](handler: PartialFunction[Throwable, b]): b =
- if (exception eq null)
- result.asInstanceOf[b]
- // !!! else if (exception is LocalReturn)
- // !!! // ...
- else if (handler isDefinedAt exception)
- handler(exception)
- else
- throw exception
-
- def Finally(handler: Unit): a =
- if (exception eq null)
- result.asInstanceOf[a]
- else
- throw exception
+ def Try[A](block: => A): Try[A] = new Try[A] with Runnable {
+ private var result: A = _
+ private var exception: Throwable =
+ try { run() ; null }
+ catch {
+ case e: ControlException => throw e // don't catch non-local returns etc
+ case e: Throwable => e
+ }
+
+ def run() { result = block }
+
+ def Catch[B >: A](handler: PartialFunction[Throwable, B]): B =
+ if (exception == null) result
+ else if (handler isDefinedAt exception) handler(exception)
+ else throw exception
+
+ def Finally(fin: => Unit): A = {
+ fin
+
+ if (exception == null) result
+ else throw exception
+ }
}
def _toString(x: Product): String =