Run method properly fails when executed code throws an exception in the main thread

git-svn-id: https://simple-build-tool.googlecode.com/svn/trunk@919 d89573ee-9141-11dd-94d4-bdf5e562f29c
This commit is contained in:
dmharrah 2009-07-30 00:15:44 +00:00
parent fa29b38b38
commit d58d29c7d9
7 changed files with 54 additions and 18 deletions

View File

@ -77,10 +77,7 @@ object Run extends ScalaRun
/** Runs the class 'mainClass' using the given classpath and options using the scala runner.*/
def run(mainClass: String, classpath: Iterable[Path], options: Seq[String], log: Logger) =
{
createSettings(log)
{
(settings: Settings) =>
{
createSettings(log) { (settings: Settings) =>
Control.trapUnit("Error during run: ", log)
{
val classpathURLs = classpath.map(_.asURL).toList
@ -97,7 +94,6 @@ object Run extends ScalaRun
}
}
}
}
/** If mainClassOption is None, then the interactive scala interpreter is started with the given classpath.
* Otherwise, the class wrapped by Some is run using the scala runner with the given classpath and
* options. */

View File

@ -29,8 +29,9 @@ object TrapExit
* the threads that were created by 'execute'.*/
val originalThreads = allThreads
val code = new ExitCode
def executeMain = try { execute } catch { case x => code.set(1); throw x }
val customThreadGroup = new ExitThreadGroup(new ExitHandler(Thread.getDefaultUncaughtExceptionHandler, originalThreads, code, log))
val executionThread = new Thread(customThreadGroup, "run-main") { override def run() { execute } }
val executionThread = new Thread(customThreadGroup, "run-main") { override def run() { executeMain } }
val originalSecurityManager = System.getSecurityManager
try

View File

@ -0,0 +1,7 @@
object Spawn
{
def main(args: Array[String])
{
error("Test error main")
}
}

View File

@ -0,0 +1,4 @@
object Spawn
{
def main(args: Array[String]) {}
}

View File

@ -0,0 +1,11 @@
object Spawn
{
def main(args: Array[String])
{
(new ThreadA).start
}
class ThreadA extends Thread
{
override def run(): Unit = error("Test error thread")
}
}

View File

@ -0,0 +1,2 @@
project.name=Test Run Errors
project.version=10.0

View File

@ -0,0 +1,15 @@
$ copy-file changes/RunSuccess.scala src/main/scala/Run.scala
[success]
> run
[success]
$ copy-file changes/RunFailureMain.scala src/main/scala/Run.scala
[success]
> run
[failure]
# an exception in a non-main thread should still be exit code 0
$ copy-file changes/ThreadRunError.scala src/main/scala/Run.scala
[success]
> run
[success]