Class CatchClause


  • public final class CatchClause
    extends Object
    A catch clause of a try statement, supporting multi-catch via multiple exception types.
    • Constructor Detail

      • CatchClause

        public CatchClause​(List<SourceType> exceptionTypes,
                           String variableName,
                           Statement body)
        Creates a catch clause over the given exception types.
        Parameters:
        exceptionTypes - caught exception types, at least one
        variableName - name of the exception variable
        body - handler body
        Throws:
        NullPointerException - if any argument is null
        IllegalArgumentException - if exceptionTypes is empty
    • Method Detail

      • of

        public static CatchClause of​(SourceType exceptionType,
                                     String variableName,
                                     Statement body)
        Creates a catch clause with a single exception type.
        Parameters:
        exceptionType - the caught exception type
        variableName - name of the exception variable
        body - handler body
        Returns:
        the new catch clause
      • multiCatch

        public static CatchClause multiCatch​(List<SourceType> types,
                                             String variableName,
                                             Statement body)
        Creates a multi-catch clause.
        Parameters:
        types - the caught exception types
        variableName - name of the exception variable
        body - handler body
        Returns:
        the new catch clause
      • isMultiCatch

        public boolean isMultiCatch()
        Returns:
        true if this clause catches more than one exception type
      • getPrimaryType

        public SourceType getPrimaryType()
        Returns:
        the first declared exception type
      • exceptionTypes

        public List<SourceType> exceptionTypes()
        Returns:
        the caught exception types, unmodifiable
      • variableName

        public String variableName()
        Returns:
        the exception variable name
      • body

        public Statement body()
        Returns:
        the handler body
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object