问题
According to akka streams docs one can handle stream failure by defining a decider that maps a Throwable
to a Strategy
:
val decider: Supervision.Decider = {
case _: ArithmeticException => Supervision.Resume
case _ => Supervision.Stop
}
I wonder if there is a way to also get access to the element that caused the error. Of course, the type of this element is unknown, but is there a way to get it even as an instance of Object
?
回答1:
The trivial way would be to catch the ArithmeticException
near where it is thrown and throw your custom exception MyDetailedArithmeticException(culprit: Int)
that would print the int
that caused the problem in the message.
来源:https://stackoverflow.com/questions/36179093/how-to-get-object-that-caused-failure-in-akka-streams