Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Boxed Error in Scala?

When I run my application, the browser shows

[ExecutionException: Boxed Error] 

It doesn't say anything about the line number, etc.

In the console, I have the following

! @6elaah0c8 - Internal server error, for (GET) [/testlearn] ->  play.api.Application$$anon$1: Execution exception[[ExecutionException: Boxed Error]]     at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.1]     at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1]     at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:326) [play_2.10.jar:2.1.1]     at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:324) [play_2.10.jar:2.1.1]     at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]     at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1] java.util.concurrent.ExecutionException: Boxed Error     at scala.concurrent.impl.Promise$.resolver(Promise.scala:52) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at scala.concurrent.impl.Promise$.scala$concurrent$impl$Promise$$resolveTry(Promise.scala:44) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:116) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at scala.concurrent.Promise$class.complete(Promise.scala:55) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:58) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [factorie-1.0.0-M4-jar-with-dependencies.jar:na] Caused by: java.lang.AssertionError: assertion failed     at scala.Predef$.assert(Predef.scala:165) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at cc.factorie.util.TraversableExtras$class.max2ByDouble(TraversableExtras.scala:95) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at cc.factorie.package$$anon$2.max2ByDouble(package.scala:148) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at cc.factorie.optimize.SampleRankExample.accumulateExampleInto(SampleRank.scala:31) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at cc.factorie.optimize.OnlineTrainer$$anonfun$processExamples$3.apply(Trainer.scala:72) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na]     at cc.factorie.optimize.OnlineTrainer$$anonfun$processExamples$3.apply(Trainer.scala:63) ~[factorie-1.0.0-M4-jar-with-dependencies.jar:na] 
like image 411
yzernik Avatar asked Jun 23 '13 20:06

yzernik


1 Answers

"Boxed Error" is Scala's response to an Error being thrown within a Future. In Java, and hence Scala, subclasses of type Error have a special meaning as Fatal errors. See Differences between Exception and Error. In short, the javadoc says:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.

Unlike throwing other Throwables within a future, when a subclass of Error is thrown, the default Scala resolver will wrap up the Error in a java.util.concurrent.ExecutionException, with the message string "Boxed Error", and complete your promise with a failure.

To quote the futures documentation http://docs.scala-lang.org/overviews/core/futures.html w.r.t. Error being thrown:

[Error] exceptions are rethrown in the thread executing the failed asynchronous computation. The rationale behind this is to prevent propagation of critical and control-flow related exceptions normally not handled by the client code and at the same time inform the client in which future the computation failed.

If you want to do something special with the Failure, the original Error that was thrown can be extracted (but not in a way particularly amenable to pattern matching), by ExecutionException#getCause()

like image 107
mseddon Avatar answered Sep 22 '22 07:09

mseddon