在我的参与者中,这些方法可能会抛出异常:
class ServerActor extends Actor {
override def receive: Receive = {
case "Start" =>
println("### actor started")
throw new Exception("My exception when starting")
case msg =>
println("### actor get other message: " + msg)
throw new Exception("another exception for other messages: " + msg)
}
}
有没有办法在一个地方处理所有的异常?我希望将它们放在一起处理,例如记录它们
发布于 2015-10-09 17:39:04
你可以试着在家长的监督策略下做到这一点:http://doc.akka.io/docs/akka/snapshot/scala/fault-tolerance.html
或者你在actor上有这样的方法:
def preRestart(reason: Throwable, message: Option[Any]): Unit
其中,原因是导致执行元崩溃的异常。
https://stackoverflow.com/questions/32984015
复制相似问题