Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework logging all RuntimeException in futures

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 => ... } }

like image 577
Michał Jurczuk Avatar asked Mar 22 '26 14:03

Michał Jurczuk


1 Answers

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() }
like image 109
icl7126 Avatar answered Mar 25 '26 05:03

icl7126



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!