Class CatchStatement

All Implemented Interfaces:
NodeMetaDataHandler

public class CatchStatement extends Statement
Represents a catch (Exception var) { } statement that handles exceptions in a try-catch block. Each catch statement specifies an exception type to handle and a code block to execute when an exception of that type is caught. The exception is bound to a variable that can be referenced within the catch block.
  • Constructor Details

    • CatchStatement

      public CatchStatement(Parameter variable, Statement code)
      Constructs a catch statement with the given exception parameter and code block.
      Parameters:
      variable - the Parameter that declares the caught exception and binds it to a variable name
      code - the Statement to execute when the exception is caught
  • Method Details

    • visit

      public void visit(GroovyCodeVisitor visitor)
      Description copied from class: ASTNode
      Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.
      Overrides:
      visit in class ASTNode
      Parameters:
      visitor - the GroovyCodeVisitor to process this node
    • getCode

      public Statement getCode()
      Returns the statement executed when the exception is caught.
      Returns:
      the catch block Statement
    • getExceptionType

      public ClassNode getExceptionType()
      Returns the exception type of this catch statement.
      Returns:
      the ClassNode representing the exception type
    • getVariable

      public Parameter getVariable()
      Returns the parameter that declares the caught exception variable.
      Returns:
      the exception Parameter
    • setCode

      public void setCode(Statement code)
      Sets the statement executed when the exception is caught.
      Parameters:
      code - the catch block Statement