com.puppycrawl.tools.checkstyle.checks.design

Class ThrowsCountCheck

Implemented Interfaces:
Configurable, Contextualizable

public final class ThrowsCountCheck
extends Check

Restricts throws statements to a specified count (default = 1).

Rationale: Exceptions form part of a methods interface. Declaring a method to throw too many differently rooted exceptions makes exception handling onerous and leads to poor programming practices such as catch (Exception). This check forces developers to put exceptions into a heirachy such that in the simplest case, only one type of exception need be checked for by a caller but allows any sub-classes to be caught specifically if necessary.

Author:
Simon Harris

Constructor Summary

ThrowsCountCheck()
Creates new instance of the check.

Method Summary

int[]
getDefaultTokens()
int
getMax()
Getter for max property.
int[]
getRequiredTokens()
void
setMax(int aMax)
Setter for max property.
void
visitToken(DetailAST aAST)

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getId, getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setId, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Constructor Details

ThrowsCountCheck

public ThrowsCountCheck()
Creates new instance of the check.

Method Details

getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check

getMax

public int getMax()
Getter for max property.
Returns:
maximum allowed throws statements.

getRequiredTokens

public int[] getRequiredTokens()
Overrides:
getRequiredTokens in interface Check

setMax

public void setMax(int aMax)
Setter for max property.
Parameters:
aMax - maximum allowed throws statements.

visitToken

public void visitToken(DetailAST aAST)
Overrides:
visitToken in interface Check