Class AssertThrowsExprGenerator

All Implemented Interfaces:
BiFunction<EK9Parser.AssertThrowsExpressionContext, String, List<IRInstr>>

public final class AssertThrowsExprGenerator extends AbstractAssertExprGenerator implements BiFunction<EK9Parser.AssertThrowsExpressionContext, String, List<IRInstr>>
IR Generation for the assertThrows expression.

Generates ASSERT_THROWS opcode for test assertions that expect a specific exception type.

Grammar: assertThrowsExpression: ASSERT_THROWS LPAREN typeDef COMMA expression RPAREN

Semantics:

  • Evaluates the expression within a try block
  • If expected exception type is caught, stores to result variable (success)
  • If no exception thrown, throws AssertionError (failure)
  • If wrong exception type thrown, rethrows it (test failure)

Used in two contexts:

  • Statement form: assertThrows(IOException, riskyOperation())
  • Expression form: ex <- assertThrows(IOException, riskyOperation())