summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-11-08 20:44:20 +0000
committerPaul Phillips <paulp@improving.org>2010-11-08 20:44:20 +0000
commit107cf1ae8e934b0ef7a6b6e819193b2166f3c44b (patch)
tree95cb815a21cf623d86476b2217f401ab8d1331c2 /src
parentb2559b3cf4516f751ad050480c50e348e03952d7 (diff)
downloadscala-107cf1ae8e934b0ef7a6b6e819193b2166f3c44b.tar.gz
scala-107cf1ae8e934b0ef7a6b6e819193b2166f3c44b.tar.bz2
scala-107cf1ae8e934b0ef7a6b6e819193b2166f3c44b.zip
Restored the stack traces I'd accidentally smot...
Restored the stack traces I'd accidentally smothered in r23426, and cleaned up ObjectRunner/ScriptRunner a bit. Closes #3978, no review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala31
-rw-r--r--src/compiler/scala/tools/nsc/ObjectRunner.scala15
-rw-r--r--src/compiler/scala/tools/nsc/ScriptRunner.scala30
-rw-r--r--src/library/scala/util/control/Exception.scala5
4 files changed, 47 insertions, 34 deletions
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index 695ce090dc..84d9eb7d22 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -8,7 +8,6 @@ package scala.tools.nsc
import java.io.IOException
import java.lang.{ClassNotFoundException, NoSuchMethodException}
-import java.lang.reflect.InvocationTargetException
import java.net.{ URL, MalformedURLException }
import scala.tools.util.PathResolver
@@ -21,7 +20,10 @@ import Properties.{ versionString, copyrightString }
* or interactive entry.
*/
object MainGenericRunner {
- def errorFn(ex: Throwable): Boolean = errorFn(ex.toString)
+ def errorFn(ex: Throwable): Boolean = {
+ ex.printStackTrace()
+ false
+ }
def errorFn(str: String): Boolean = {
Console println str
false
@@ -83,23 +85,18 @@ object MainGenericRunner {
case "guess" => ScalaClassLoader.classExists(classpath, thingToRun)
}
- if (isObjectName)
- try {
- ObjectRunner.run(classpath, thingToRun, command.arguments)
- true
- }
- catch {
- case e @ (_: ClassNotFoundException | _: NoSuchMethodException) => errorFn(e)
- case e: InvocationTargetException => errorFn(e.getCause)
- }
- else
- try {
- ScriptRunner.runScript(settings, thingToRun, command.arguments)
+ if (isObjectName) {
+ ObjectRunner.runAndCatch(classpath, thingToRun, command.arguments) match {
+ case Left(ex) => errorFn(ex)
+ case _ => true
}
- catch {
- case e: IOException => errorFn(e.getMessage)
- case e: SecurityException => errorFn(e)
+ }
+ else {
+ ScriptRunner.runScriptAndCatch(settings, thingToRun, command.arguments) match {
+ case Left(ex) => errorFn(ex)
+ case Right(b) => b
}
+ }
}
}
}
diff --git a/src/compiler/scala/tools/nsc/ObjectRunner.scala b/src/compiler/scala/tools/nsc/ObjectRunner.scala
index f2ddc84445..987a6b0ba0 100644
--- a/src/compiler/scala/tools/nsc/ObjectRunner.scala
+++ b/src/compiler/scala/tools/nsc/ObjectRunner.scala
@@ -8,6 +8,7 @@ package scala.tools.nsc
import java.net.URL
import util.ScalaClassLoader
+import java.lang.reflect.InvocationTargetException
/** An object that runs another object specified by name.
*
@@ -24,10 +25,22 @@ object ObjectRunner {
* specified classpath and argument list.
*
* @throws ClassNotFoundException
- * @throws NoSuchMethodError
+ * @throws NoSuchMethodException
* @throws InvocationTargetException
*/
def run(urls: List[URL], objectName: String, arguments: Seq[String]) {
(ScalaClassLoader fromURLs urls).run(objectName, arguments)
}
+
+ /** Catches exceptions enumerated by run (in the case of InvocationTargetException,
+ * unwrapping it) and returns it any thrown in Left(x).
+ */
+ def runAndCatch(urls: List[URL], objectName: String, arguments: Seq[String]): Either[Throwable, Unit] = {
+ try Right(run(urls, objectName, arguments))
+ catch {
+ case e: ClassNotFoundException => Left(e)
+ case e: NoSuchMethodException => Left(e)
+ case e: InvocationTargetException => Left(e.getCause match { case null => e ; case cause => cause })
+ }
+ }
}
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala
index 23d4e32a6e..6f5f2936a8 100644
--- a/src/compiler/scala/tools/nsc/ScriptRunner.scala
+++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -13,7 +13,6 @@ import java.io.{
}
import java.io.{ File => JFile }
import io.{ Directory, File, Path, PlainFile }
-import java.lang.reflect.InvocationTargetException
import java.net.URL
import java.util.jar.{ JarEntry, JarOutputStream }
@@ -250,17 +249,9 @@ object ScriptRunner {
val pr = new PathResolver(settings)
val classpath = File(compiledLocation).toURL +: pr.asURLs
- try {
- ObjectRunner.run(classpath, scriptMain(settings), scriptArgs)
- true
- }
- catch {
- case e @ (_: ClassNotFoundException | _: NoSuchMethodException) =>
- Console println e
- false
- case e: InvocationTargetException =>
- e.getCause.printStackTrace
- false
+ ObjectRunner.runAndCatch(classpath, scriptMain(settings), scriptArgs) match {
+ case Left(ex) => Console println ex ; false
+ case _ => true
}
}
@@ -280,6 +271,21 @@ object ScriptRunner {
throw new IOException("no such file: " + scriptFile)
}
+ /** Calls runScript and catches the enumerated exceptions, routing
+ * them to Left(ex) if thrown.
+ */
+ def runScriptAndCatch(
+ settings: GenericRunnerSettings,
+ scriptFile: String,
+ scriptArgs: List[String]): Either[Throwable, Boolean] =
+ {
+ try Right(runScript(settings, scriptFile, scriptArgs))
+ catch {
+ case e: IOException => Left(e)
+ case e: SecurityException => Left(e)
+ }
+ }
+
/** Run a command
*
* @return true if compilation and execution succeeded, false otherwise.
diff --git a/src/library/scala/util/control/Exception.scala b/src/library/scala/util/control/Exception.scala
index 356b11df51..87aa5a9888 100644
--- a/src/library/scala/util/control/Exception.scala
+++ b/src/library/scala/util/control/Exception.scala
@@ -16,10 +16,7 @@ import collection.immutable.List
* @author Paul Phillips
*/
-import java.lang.reflect.InvocationTargetException
-
-object Exception
-{
+object Exception {
// We get lots of crashes using this, so for now we just use Class[_]
// type ExClass = Class[_ <: Throwable]