Package org.codehaus.groovy.ast.stmt

# Class CatchStatement

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.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 Summary

  Constructors
  Constructor
  Description
  `CatchStatement(Parameter variable, Statement code)`
  Constructs a catch statement with the given exception parameter and code block.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Statement`
  `getCode()`
  Returns the statement executed when the exception is caught.
  `ClassNode`
  `getExceptionType()`
  Returns the exception type of this catch statement.
  `Parameter`
  `getVariable()`
  Returns the parameter that declares the caught exception variable.
  `void`
  `setCode(Statement code)`
  Sets the statement executed when the exception is caught.
  `void`
  `visit(GroovyCodeVisitor visitor)`
  Accepts a code visitor for AST traversal and transformation.

  ### Methods inherited from class org.codehaus.groovy.ast.stmt.Statement

  `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## 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`