There is also:
f recover { case cause => throw new Exception("Something went wrong", cause) }
Since Scala 2.12 you can do:
f transform {
case s @ Success(_) => s
case Failure(cause) => Failure(new Exception("Something went wrong", cause))
}
or
f transform { _.transform(Success(_), cause => Failure(new Exception("Something went wrong", cause)))}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…