It seems like a pretty straight forward problem, but I would like to write a stack trace when the top-level error handler in Scalatra starts. I intentionally throw an exception in one of my methods, doing something as trivial as:
throw new IllegalArgumentException
In the error handler, the code is as follows:
error { case e => { val logger = LoggerFactory.getLogger(getClass) logger.info("an exception occurred: " + e.getStackTrace()) logger.info("the request body is: " + request) NotFound("An error occurred, please contact support") } }
The error handler itself is specific to Scalatra, but I'm sure that the answer I'm looking for can be solved using any Scala vanilla technique. Is there something I can do at this point to grab the stack? I'm not sure if the request is in the same thread as the error handler, otherwise there might be some kind of answer. e.getStackTrace() gives me [Ljava.lang.StackTraceElement;@1f6b6954
What is the best way to get the stack trace printed here so I can log and view it to fix errors in my horrible code?
scala exception-handling scalatra
randombits
source share