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