Map the Exception of a failed Future

前端 未结 2 1320
感动是毒
感动是毒 2020-12-28 12:58

What\'s the cleanest way to map the Exception of a failed Future in scala?

Say I have:

import scala.concurrent         


        
2条回答
  •  Happy的楠姐
    2020-12-28 13:24

    You could try recoverWith as in:

    f recoverWith{
      case ex:Exception => Future.failed(new Exception("foo", ex))
    }
    

提交回复
热议问题