Class TryCatchAsmGenerator


final class TryCatchAsmGenerator extends AbstractControlFlowAsmGenerator
Specialized generator for EK9 try/catch/finally statements. Handles CONTROL_FLOW_CHAIN with chain_type: "TRY_CATCH_FINALLY".

JVM Bytecode Pattern:

try_start:
  [try block instructions]
  goto after_handlers            ; Normal exit
try_end:
catch_start_1:
  [catch block 1 instructions]
  goto after_handlers
catch_end_1:
catch_start_2:
  [catch block 2 instructions]
  goto after_handlers
catch_end_2:
after_handlers:
  [finally block if present]

Exception Table:
  from    to      target        type
  try_start try_end catch_start_1 ExceptionType1
  try_start try_end catch_start_2 ExceptionType2

Stack Frame Invariant: Stack is empty before try, after each handler, and after the entire statement.

  • Constructor Details

  • Method Details

    • generate

      public void generate(ControlFlowChainInstr instr)
      Generate bytecode for try/catch/finally.

      Control Flow:

      1. Create labels for exception handlers
      2. Register exception handlers with JVM (visitTryCatchBlock)
      3. Execute try block
      4. Jump to after handlers (normal path)
      5. Execute each catch handler
      6. Execute finally block (if present)

      Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty

      Parameters:
      instr - CONTROL_FLOW_CHAIN instruction with TRY_CATCH_FINALLY type