Open
Description
The following Scala 2 warning is not issued by dotty:
scala> try ??? catch { case _ => 42 } // Scala 2
^
warning: This catches all Throwables. If this is really intended, use `case _ : Throwable` to clear this warning.
Catch using any Function
Dotty allows try e catch f
where f
is any Function
(not PartialFunction
). Why is this considered desirable? Quoting @SethTisue
Allowing
Function
instead of requiringPartialFunction
only encourages catchingThrowable
, which is pretty much never a good idea (because of e.g.OutOfMemoryError
).
See #8664.
Scala 3 doesn't issue a "catches all Throwables" warning in this case.
scala> try ??? catch println // Scala 3
scala.NotImplementedError: an implementation is missing