public class AvoidHidingCauseExceptionCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
This check prevents new exception throwing inside try/catch blocks without providing current exception cause. New exception should propagate up to a higher-level handler with exact cause to provide a full stack trace for the problem.
Rationale: When handling exceptions using try/catch blocks junior developers may lose the original/cause exception object and information associated with it.
Examples:
public void foo() {
RuntimeException r;
catch (java.lang.Exception e) {
//your code
throw r;
}
}
2. Cause exception will be lost because current catch block
doesn`t contains another exception throwing.
catch (IllegalStateException e) {
//your code
throw new RuntimeException();
}
catch (IllegalStateException e) {
//your code
throw new RuntimeException("Runtime Exception!");
}
| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
AvoidHidingCauseExceptionCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST detailAST) |
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeveritypublic static final String MSG_KEY
public int[] getDefaultTokens()
getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getAcceptableTokens()
getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getRequiredTokens()
getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST detailAST)
visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheckCopyright © 2021. All rights reserved.