Skip to content

Safer Exceptions throws clauses have stopped working #17040

Open
@reftrans

Description

@reftrans

Compiler version

The problem is introduced in e422066.

Minimized code

import language.experimental.saferExceptions
def fail(): Unit throws Exception = throw Exception()

Output

3 |def fail(): Unit throws Exception = throw Exception()
  |                                    ^^^^^^^^^^^^^^^^^
  |                                    The capability to throw exception Exception is missing.
  |                                    The capability can be provided by one of the following:
  |                                     - Adding a using clause `(using CanThrow[Exception])` to the definition of the enclosing method
  |                                     - Adding `throws Exception` clause after the result type of the enclosing method
  |                                     - Wrapping this piece of code with a `try` block that catches Exception
  |
  |                                    The following import might fix the problem:
  |
  |                                      import unsafeExceptions.canThrowAny
  |
1 error found

It compiles normally with a using CanThrow[Exception] clause instead of throws Exception.

Expectation

Same behavior as for using clause.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions