How to get object that caused failure in Akka Streams?

回眸只為那壹抹淺笑 提交于 2021-02-08 02:12:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!