Skip to content

Missing "catches all Throwables" warning #11019

Open
@lrytz

Description

@lrytz

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 requiring PartialFunction only encourages catching Throwable, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions