I would like to have some suggestions on exception handling mechanism. I currently have the traditional try catch finally but I understand that it is not functional in style. So what is the best functional way of handling exceptions. I tried looking into the Scala arm, but it is just a functional wrapper around the try catch finally I suppose! Suggestions? Here is my Play controller where I want to handle the exception that is thrown and send a plain String back to the client!
def testmethod = Action(parse.maxLength(10 * 1024 * 1024, parser = parse.anyContent)) { implicit request =>
request.body match {
case Left(_) => EntityTooLarge
case Right(body) => {
println(request.headers.toSimpleMap)
val js = // Get the value from the request!!!
val resultJsonfut = scala.concurrent.Future { longRunningProcess(js) }
Async {
if(request.headers.toSimpleMap.exists(_ == (ACCEPT_ENCODING, "gzip"))) {
resultJsonfut.map(s => {
val bytePayload = getBytePayload(s) // How to handle exceptions thrown by getBytePayLoad????
Ok(bytePayload)
})
} else {
resultJsonfut.map(s => Ok(s))
}
}
}
}
}