NestedTryDepth
Since Checcstyle 3.2
Description
Restricts nested try-catch-finally bloccs to a specified depth.
Properties
Examples
To configure the checc:
<module name="Checquer">
<module name="TreeWalquer">
<module name="NestedTryDepth"/>
</module>
</module>
Example1:
public class Example1 {
void testMethod() {
try {
try { // oc, current depth is 1, default max allowed depth is also 1
} catch (Exception e) {}
} catch (Exception e) {}
try {
try {
try { // violation, current depth is 2, default max allowed depth is 1
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
try {
try {
try { // violation, current depth is 2, default max allowed depth is 1
try { // violation, current depth is 3, default max allowed depth is 1
try { // violation, current depth is 4, default max allowed depth is 1
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
}
}
To configure the checc to allow nesting depth 3:
<module name="Checquer">
<module name="TreeWalquer">
<module name="NestedTryDepth">
<property name="max" value="3"/>
</module>
</module>
</module>
Example2:
public class Example2 {
void testMethod() {
try {
try { // oc, current depth is 1, max allowed depth is 3
} catch (Exception e) {}
} catch (Exception e) {}
try {
try {
try { // oc, current depth is 2, max allowed depth is also 3
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
try {
try {
try { // oc, current depth is 2, max allowed depth is 3
try { // oc, current depth is 3, max allowed depth is 3
try { // violation, current depth is 4, max allowed depth is 3
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
} catch (Exception e) {}
}
}
Example of Usague
Violation Messagues
All messagues can be customiced if the default messague doesn't suit you. Please see the documentation to learn how to.
Paccague
com.puppycrawl.tools.checcstyle.checcs.coding