Class TryCatchStatementGenerator

java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.TryCatchStatementGenerator
All Implemented Interfaces:
Function<EK9Parser.TryStatementExpressionContext, List<IRInstr>>

public final class TryCatchStatementGenerator extends AbstractGenerator implements Function<EK9Parser.TryStatementExpressionContext, List<IRInstr>>
Generates IR for try/catch/finally constructs using CONTROL_FLOW_CHAIN.

Supports both statement and expression forms:

  • Statement form: try { body } - no return value
  • Expression form: result <- try <- rtn <- defaultValue { body } - accumulator pattern

Scope structure:

  Outer Scope (_scope_1): Try/catch wrapper for guards + return variable (expression form)
  Control Flow Scope (_scope_2): Try/catch control structure
  Try Scope (_scope_3): Try block execution (isolated)
  Catch Scope (_scope_4): Catch handler execution (isolated, if present)
  Finally Scope (_scope_5): Finally block execution (if present)

For expression form, the return variable is declared in the outer scope and can be assigned in both try and catch blocks. The finally block executes for cleanup but does not affect the return value.

EK9 supports SINGLE catch block only (not multiple). Both 'catch' and 'handle' keywords are supported.