Reputation: 1033
There is a static exception path on class Spark, but it only takes something that extends from Exception. If an error occurs that is a Throwable, but does not extend Exception, there appears to be no way to catch it in the Spark API to log or handle it before a 500 is returned to client.
Example of a common type of Throwable that can't be mapped to Spark.exception: java.lang.ExceptionInInitializerError
Any way to get hold of these in Spark before they disappear out to client, without wrapping the functions of every route in a try/catch(Throwable)?
Upvotes: 0
Views: 1728
Reputation: 6813
You can't catch Throwable
errors in Spark.
The thing is that Throwable
includes Error
Error is programmatically unrecoverable and therefore is usually not to be caught.
On the other hand Exception
is programmatically recoverable, and therefore something that you may want to catch.
I recommend you reading
You should ask yourself why are you trying to catch Throwable
's and maybe modify that part (if that code of yours).
Upvotes: 2