diff options
author | Raphael Jolly <rjolly@users.sourceforge.net> | 2013-05-16 09:52:04 +0200 |
---|---|---|
committer | Raphael Jolly <rjolly@users.sourceforge.net> | 2013-05-16 10:08:40 +0200 |
commit | 0bece25e87b80b5e608691ee619754453afdf9a1 (patch) | |
tree | 58729a11ef0e6d2aa41bbc96d0f95d3cb0ed0e8c | |
parent | 6a3efe3b3e83c37182268f0e0bab9acc69653115 (diff) | |
download | scala-0bece25e87b80b5e608691ee619754453afdf9a1.tar.gz scala-0bece25e87b80b5e608691ee619754453afdf9a1.tar.bz2 scala-0bece25e87b80b5e608691ee619754453afdf9a1.zip |
ScriptEngine.eval() forwards Error instead of new ScriptException
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/IMain.scala | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala index 66129e0be8..3e13c0bab2 100644 --- a/src/repl/scala/tools/nsc/interpreter/IMain.scala +++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala @@ -597,11 +597,19 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set private class WrappedRequest(val req: Request) extends CompiledScript { var recorded = false + /** In Java we would have to wrap any checked exception in the declared + * ScriptException. Runtime exceptions and errors would be ok and would + * not need to be caught. So let us do the same in Scala : catch and + * wrap any checked exception, and let runtime exceptions and errors + * escape. We could have wrapped runtime exceptions just like other + * exceptions in ScriptException, this is a choice. + */ @throws(classOf[ScriptException]) def eval(context: ScriptContext): Object = { val result = req.lineRep.evalEither match { + case Left(e: RuntimeException) => throw e case Left(e: Exception) => throw new ScriptException(e) - case Left(_) => throw new ScriptException("run-time error") + case Left(e) => throw e case Right(result) => result.asInstanceOf[Object] } if (!recorded) { |