Skip to content

Generate multi-exception catch in byte code #24774

@noti0na1

Description

@noti0na1
class A extends Exception
class B extends Exception

def f =
  try
    throw new Exception()
  catch
    case e: (A | B) =>
      println("matched A or B")
    case _ =>
      println("not matched")

After genBCode:

def f(): Unit =
  try throw new Exception() catch 
    {
      case ex1 @ _ =>
        matchResult1[Unit]: 
          {
            case val x1: Throwable = ex1
            if x1.isInstanceOf[A] || x1.isInstanceOf[B] then
              {
                case val x2: Exception = x1.asInstanceOf[Exception]
                case val e: Exception = x2
                {
                  return[matchResult1] println("matched A or B")
                }
              }
             else ()
            {
              return[matchResult1] println("not matched")
            }
          }
    }

We can generate a multi-exception catch for the simple exception union types like in Java, instead of handling in a new pattern match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions