diff options
author | Paul Phillips <paulp@improving.org> | 2010-11-08 20:44:20 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-11-08 20:44:20 +0000 |
commit | 107cf1ae8e934b0ef7a6b6e819193b2166f3c44b (patch) | |
tree | 95cb815a21cf623d86476b2217f401ab8d1331c2 /src/compiler/scala/tools/nsc/ObjectRunner.scala | |
parent | b2559b3cf4516f751ad050480c50e348e03952d7 (diff) | |
download | scala-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/compiler/scala/tools/nsc/ObjectRunner.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ObjectRunner.scala | 15 |
1 files changed, 14 insertions, 1 deletions
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 }) + } + } } |