Class IllegalCatchExtendedCheck

  • All Implemented Interfaces:
    com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable

    public final class IllegalCatchExtendedCheck
    extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
    Catching java.lang.Exception, java.lang.Error or java.lang.RuntimeException is almost never acceptable.
    Since:
    1.8.0
    Author:
    Simon Harris
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String MSG_KEY
      Warning message key.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int[] getAcceptableTokens()  
      int[] getDefaultTokens()  
      int[] getRequiredTokens()  
      com.puppycrawl.tools.checkstyle.api.DetailAST getThrowAST​(com.puppycrawl.tools.checkstyle.api.DetailAST parentAST)
      Looking for the keyword "throw" among current (aParentAST) node childs.
      protected boolean isIllegalClassName​(String ident)
      Checks if given class is illegal.
      void setAllowRethrow​(boolean value)
      Enable(false) | Disable(true) warnings for "catch" blocks containing rethrowing an exception.
      void setAllowThrow​(boolean value)
      Enable(false) | Disable(true) warnings for "catch" blocks containing throwing an exception.
      void setIllegalClassNames​(String... classNames)
      Set the list of illegal classes.
      void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST detailAST)  
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck

        beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

        finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        configure, contextualize, getConfiguration, setupChild
    • Constructor Detail

      • IllegalCatchExtendedCheck

        public IllegalCatchExtendedCheck()
    • Method Detail

      • setIllegalClassNames

        public void setIllegalClassNames​(String... classNames)
        Set the list of illegal classes.
        Parameters:
        classNames - array of illegal exception classes
      • setAllowThrow

        public void setAllowThrow​(boolean value)
        Enable(false) | Disable(true) warnings for "catch" blocks containing throwing an exception.
        Parameters:
        value - Disable warning for throwing
      • setAllowRethrow

        public void setAllowRethrow​(boolean value)
        Enable(false) | Disable(true) warnings for "catch" blocks containing rethrowing an exception.
        Parameters:
        value - Disable warnings for rethrowing
      • getDefaultTokens

        public int[] getDefaultTokens()
        Specified by:
        getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Specified by:
        getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getRequiredTokens

        public int[] getRequiredTokens()
        Specified by:
        getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • visitToken

        public void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST detailAST)
        Overrides:
        visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getThrowAST

        public com.puppycrawl.tools.checkstyle.api.DetailAST getThrowAST​(com.puppycrawl.tools.checkstyle.api.DetailAST parentAST)
        Looking for the keyword "throw" among current (aParentAST) node childs.
        Parameters:
        parentAST - - the current parent node.
        Returns:
        null if the "throw" keyword was not found or the LITERAL_THROW DetailAST otherwise
      • isIllegalClassName

        protected boolean isIllegalClassName​(String ident)
        Checks if given class is illegal.
        Parameters:
        ident - ident to check.
        Returns:
        true if given ident is illegal.