View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="IllegalCatch">
5         <property name="illegalClassNames"
6              value="ArithmeticException,OutOfMemoryError"/>
7       </module>
8     </module>
9   </module>
10  */
11  package com.puppycrawl.tools.checkstyle.checks.coding.illegalcatch;
12  
13  // xdoc section -- start
14  class Example2 {
15    void exampleMethod1() {
16      try {
17        // some code here
18      } catch (Exception e) {
19  
20      }
21    }
22  
23    void exampleMethod2() {
24      try {
25        // some code here
26      } catch (ArithmeticException e) {
27        // violation above, 'Catching 'ArithmeticException' is not allowed'
28      } catch(Exception e){
29  
30      }
31    }
32  
33    void exampleMethod3() {
34      try {
35        // some code here
36      } catch (NullPointerException e) {
37      } catch (OutOfMemoryError e) {
38        // violation above, 'Catching 'OutOfMemoryError' is not allowed'
39      }
40    }
41  
42    void exampleMethod4() {
43      try {
44        // some code here
45      } catch (ArithmeticException | NullPointerException e) {
46        // violation above, 'Catching 'ArithmeticException' is not allowed'
47      }
48    }
49  
50    void exampleMethod5(){
51      try {
52        // some code here
53      } catch (OutOfMemoryError e) {
54        // violation above, 'Catching 'OutOfMemoryError' is not allowed'
55      }
56    }
57  }
58  // xdoc section -- end