I am using Akka and would like to run some code for all cases of a PartialFunction. For actor supervision, I have something like:
val supervisorStrategy = OneForOneStrategy() {
case npe: NullPointerException => Stop
case re: RuntimeException => Restart
}
The only way I have found to run some code for all cases without having to write it again at every case, is:
val pf = new PartialFunction[Throwable, Directive] {
def apply(throwable: Throwable) = {
doSomething(throwable)
throwable match {
case NullPointerException => Stop
case RuntimeException => Restart
}
}
def isDefinedAt(throwable: Throwable) = true
}
val supervisorStrategy = OneForOneStrategy()(pf)
I have looked around and to other answers (like this one) but couldn't figure out any alternative way to the one I came up with.