summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/MainGenericRunner.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-11-01 20:30:22 +0000
committerPaul Phillips <paulp@improving.org>2010-11-01 20:30:22 +0000
commitc0b74d9bcdf3e9d4601b6057dd8ddfd556ef757c (patch)
tree56ee95a63ffc694f8d8e5a8e3f1711e4262f8eab /src/compiler/scala/tools/nsc/MainGenericRunner.scala
parent2f851bd1f7484c0650158ef335c019f8f7496f2a (diff)
downloadscala-c0b74d9bcdf3e9d4601b6057dd8ddfd556ef757c.tar.gz
scala-c0b74d9bcdf3e9d4601b6057dd8ddfd556ef757c.tar.bz2
scala-c0b74d9bcdf3e9d4601b6057dd8ddfd556ef757c.zip
Don't call exit from MainGenericRunner in a way...
Don't call exit from MainGenericRunner in a way which is impossible to avoid. Closes #3901, no review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/MainGenericRunner.scala')
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index 96d6846d64..695ce090dc 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -21,16 +21,19 @@ import Properties.{ versionString, copyrightString }
* or interactive entry.
*/
object MainGenericRunner {
+ def errorFn(ex: Throwable): Boolean = errorFn(ex.toString)
+ def errorFn(str: String): Boolean = {
+ Console println str
+ false
+ }
+
def main(args: Array[String]) {
- def errorFn(str: String) = Console println str
- def exitSuccess: Nothing = exit(0)
- def exitFailure(msg: Any = null): Nothing = {
- if (msg != null) errorFn(msg.toString)
+ if (!process(args))
exit(1)
- }
- def exitCond(b: Boolean): Nothing = if (b) exitSuccess else exitFailure(null)
+ }
- val command = new GenericRunnerCommand(args.toList, errorFn _)
+ def process(args: Array[String]): Boolean = {
+ val command = new GenericRunnerCommand(args.toList, (x: String) => errorFn(x))
import command.settings
def sampleCompiler = new Global(settings) // def so its not created unless needed
@@ -64,12 +67,13 @@ object MainGenericRunner {
*/
val fullArgs = command.thingToRun.toList ::: command.arguments
- exitCond(ScriptRunner.runCommand(settings, combinedCode, fullArgs))
+ return ScriptRunner.runCommand(settings, combinedCode, fullArgs)
}
else command.thingToRun match {
case None =>
- // Questionably, we start the interpreter when there are no arguments.
+ // We start the repl when no arguments are given.
new InterpreterLoop main settings
+ true // not actually reached in general
case Some(thingToRun) =>
val isObjectName =
@@ -80,18 +84,21 @@ object MainGenericRunner {
}
if (isObjectName)
- try ObjectRunner.run(classpath, thingToRun, command.arguments)
+ try {
+ ObjectRunner.run(classpath, thingToRun, command.arguments)
+ true
+ }
catch {
- case e @ (_: ClassNotFoundException | _: NoSuchMethodException) => exitFailure(e)
- case e: InvocationTargetException =>
- e.getCause.printStackTrace
- exitFailure()
+ case e @ (_: ClassNotFoundException | _: NoSuchMethodException) => errorFn(e)
+ case e: InvocationTargetException => errorFn(e.getCause)
}
else
- try exitCond(ScriptRunner.runScript(settings, thingToRun, command.arguments))
+ try {
+ ScriptRunner.runScript(settings, thingToRun, command.arguments)
+ }
catch {
- case e: IOException => exitFailure(e.getMessage)
- case e: SecurityException => exitFailure(e)
+ case e: IOException => errorFn(e.getMessage)
+ case e: SecurityException => errorFn(e)
}
}
}