From 0bece25e87b80b5e608691ee619754453afdf9a1 Mon Sep 17 00:00:00 2001 From: Raphael Jolly Date: Thu, 16 May 2013 09:52:04 +0200 Subject: ScriptEngine.eval() forwards Error instead of new ScriptException --- src/repl/scala/tools/nsc/interpreter/IMain.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) { -- cgit v1.2.3