summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-11-17 12:44:39 +0000
committerpaltherr <paltherr@epfl.ch>2004-11-17 12:44:39 +0000
commit35c612c5c240555649428fa029ae1c6b9b85ebeb (patch)
treee6a99f7473a0a983e499ce6aef31f2f8427859e1 /sources
parent2968ffe5e0441c05a571e46a70d649718eaaeae3 (diff)
downloadscala-35c612c5c240555649428fa029ae1c6b9b85ebeb.tar.gz
scala-35c612c5c240555649428fa029ae1c6b9b85ebeb.tar.bz2
scala-35c612c5c240555649428fa029ae1c6b9b85ebeb.zip
- Removed ResultOrException
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/runtime/ResultOrException.java40
-rw-r--r--sources/scala/runtime/RunTime.java12
-rw-r--r--sources/scala/runtime/ScalaRunTime.scala42
3 files changed, 39 insertions, 55 deletions
diff --git a/sources/scala/runtime/ResultOrException.java b/sources/scala/runtime/ResultOrException.java
deleted file mode 100644
index 4961c785d7..0000000000
--- a/sources/scala/runtime/ResultOrException.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-package scala.runtime;
-
-/** @meta class [?A] extends java.lang.Object;
- */
-public class ResultOrException {
-
- /** @meta field ?A;
- */
- public Object result;
-
- public Throwable exc;
-
- /** @meta constr(?A, java.lang.Throwable);
- */
- ResultOrException(Object result, Throwable exc) {
- this.result = result;
- this.exc = exc;
- }
-
- /** @meta method [?A] (def ?A) scala.runtime.ResultOrException[?A];
- */
- public static ResultOrException tryBlock(scala.Function0 block) {
- try {
- return new ResultOrException(block.apply(), null);
- } catch (Throwable ex) {
- return new ResultOrException(null, ex);
- }
- }
-}
-
diff --git a/sources/scala/runtime/RunTime.java b/sources/scala/runtime/RunTime.java
index fbc08e716e..b5b8e98fb7 100644
--- a/sources/scala/runtime/RunTime.java
+++ b/sources/scala/runtime/RunTime.java
@@ -72,6 +72,18 @@ public abstract class RunTime {
}
//########################################################################
+ // Public Functions - Catching exceptions
+
+ public static Throwable tryCatch(Runnable runnable) {
+ try {
+ runnable.run();
+ return null;
+ } catch (Throwable exception) {
+ return exception;
+ }
+ }
+
+ //########################################################################
// Public Functions - Boxing primitives
public static Unit box_uvalue( ) {
diff --git a/sources/scala/runtime/ScalaRunTime.scala b/sources/scala/runtime/ScalaRunTime.scala
index 7a13eac8c9..b2920999e6 100644
--- a/sources/scala/runtime/ScalaRunTime.scala
+++ b/sources/scala/runtime/ScalaRunTime.scala
@@ -12,20 +12,32 @@ package scala.runtime;
object ScalaRunTime {
- class Try[a](r: scala.runtime.ResultOrException[a]) {
- def Catch[b >: a](handler: PartialFunction[Throwable, b]): b =
- if (r.exc == null)
- r.result.asInstanceOf[b]
- else if (/*!(r.exc is NonLocalReturn) && */handler isDefinedAt r.exc)
- handler(r.exc)
- else
- throw r.exc;
-
- def Finally(handler: Unit): a =
- if (r.exc == null) r.result.asInstanceOf[a] else throw r.exc;
- }
-
- def Try[a](def/*!!!*/ block: a): Try[a] =
- new Try(ResultOrException.tryBlock(block));
+ trait Try[a] {
+ def Catch[b >: a](handler: PartialFunction[Throwable, b]): b;
+ def Finally(handler: Unit): a;
+ }
+
+ def Try[a](block: => a): Try[a] = new Try[a] with Runnable {
+ var result: a = _;
+ var exception: Throwable = RunTime.tryCatch(this);
+
+ def run(): Unit = result = block;
+
+ def Catch[b >: a](handler: PartialFunction[Throwable, b]): b =
+ if (exception == 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 == null)
+ result.asInstanceOf[a]
+ else
+ throw exception;
+ }
}