Calling Future { throw ex } and Future.failed(ex) will produce an equivalent result. However, using Future.failed more efficient. If we look at this snippet from Future.apply (from here in the source ):
promise complete { try Success(body) catch { case NonFatal(e) => Failure(e) } }
We notice that (as expected) it depends on the try...catch . As you know, they have heavy overhead compared to regular code. The Future.failed method is essentially a shortcut to this, without the expense of actually throwing an exception.
Ben reich
source share