I'm creating application in Play Framework 2.2 using Scala, and I want to save in my log files all RuntimeException.
When I add to code something like:
future.map { f =>
throw new NullPointerException("bad things happen")
}
I have any info in my logs. How should I configure my log4j, and why such behavior is by default?
=== Update
I can catch this exception inside, but maybe there is some better way of catching it outside:
future.map { f =>
try {
...
throw new NullPointerException("bad things happen")
} catch {
case e:RuntimeException =>
...
}
}
Instead of using try-catch you can call recover method of the future and print stack trace there:
future.map { f =>
throw new NullPointerException("bad things happen")
}.recover { case ex => ex.printStackTrace() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With