Skip to content

Catch clause always require case on newline #14061

Closed
@tgodzik

Description

@tgodzik

Compiler version

3.1.0

Minimized code

def main(args: Array[String]): Unit =
  val bar: PartialFunction[Throwable, Unit] =
    case e: IllegalArgumentException => e.printStackTrace
    case e: Throwable => e.printStackTrace
  try
    println("a")
  catch
    bar
  finally
    println("a")

Output

[error] -- [E000] Syntax Error: /home/tgodzik/Documents/workspaces/scala3-example-project/src/main/scala/Main.scala:9:2 
[error] 9 |  catch
[error]   |  ^^^^^
[error]   |  The catch block does not contain a valid expression, try
[error]   |  adding a case like - case e: Exception => to the block

Expectation

Test compiles, according to https://docs.scala-lang.org/scala3/reference/syntax.html#expressions ‘catch’ (Expr | ExprCaseClause) -> catch should be possible to follow by an expression, newline should not cause any issues.

Is this an expected behaviour?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions