summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-05-29 18:46:45 +0000
committerPaul Phillips <paulp@improving.org>2009-05-29 18:46:45 +0000
commitfcc62d3da6142acaea96f67fc6ee296085c1971b (patch)
tree8e0ee0b6d678c8e2931073a1ea4d7395476a40e5 /src/compiler
parent488f986078c4f80381849f66d30d2e24818dbff9 (diff)
downloadscala-fcc62d3da6142acaea96f67fc6ee296085c1971b.tar.gz
scala-fcc62d3da6142acaea96f67fc6ee296085c1971b.tar.bz2
scala-fcc62d3da6142acaea96f67fc6ee296085c1971b.zip
Continuing to refine exception composition.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 206067efd8..c4f4a38ff8 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -16,7 +16,7 @@ import scala.collection.immutable.ListSet
import scala.collection.mutable
import scala.collection.mutable.{ ListBuffer, HashSet, ArrayBuffer }
import scala.util.{ ScalaClassLoader, URLClassLoader }
-import scala.util.control.Exception.reflectionUnwrapper
+import scala.util.control.Exception.{ Catcher, catching, unwrapping }
import io.{ PlainFile, VirtualDirectory }
import reporters.{ ConsoleReporter, Reporter }
@@ -763,22 +763,19 @@ class Interpreter(val settings: Settings, out: PrintWriter)
def loadAndRun: (String, Boolean) = {
val resultObject: Class[_] = loadByName(resultObjectName)
val resultValMethod: reflect.Method = resultObject getMethod "result"
- lazy val pair = (resultValMethod.invoke(resultObject).toString, true)
+ def invocation = (resultValMethod.invoke(resultObject).toString, true)
- def unwrap(e: Throwable): Throwable = e match {
- case (_: InvocationTargetException | _: ExceptionInInitializerError) if e.getCause ne null =>
- unwrap(e.getCause)
- case _ => e
+ def onErr: Catcher[(String, Boolean)] = { case t: Throwable =>
+ beQuietDuring { bind("lastException", "java.lang.Throwable", t) }
+ (stringFrom(t.printStackTrace(_)), false)
}
- (reflectionUnwrapper either pair) match {
- case Left(e) =>
- val unwrapped = unwrap(e)
- beQuietDuring { bind("lastException", "java.lang.Throwable", unwrapped) }
-
- (stringFrom(unwrapped.printStackTrace(_)), false)
- case Right((res, success)) => (res, success)
- }
+ catching(onErr) invokeOn(
+ unwrapping(
+ classOf[InvocationTargetException],
+ classOf[ExceptionInInitializerError]
+ ) invokeOn invocation
+ )
}
}