aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-education-plugin/src/main/resources/org/sonar/education/4codeSnippets.html
blob: b14c53f8602ada7470eaa6f8cba36da21c7eb620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<p>A <code>catch</code> clause that only rethrows the caught exception has the same effect as omitting the <code>catch</code> altogether and letting
    it bubble up automatically, but with more code and the additional detriment of leaving maintainers scratching their heads.</p>
<p>Such clauses should either be eliminated or populated with the appropriate logic.</p>
<h2>Noncompliant Code Example</h2>
<pre class="diff-id-1 diff-noncompliant">try {
  doSomething();
} catch (ex) {  // Noncompliant
  throw ex;
}
</pre>
<h2>Compliant Solution</h2>
<pre class="diff-id-1 diff-compliant">try {
  doSomething();
} catch (ex) {
  console.err(ex);
  throw ex;
}
</pre>

<h2>Noncompliant Code Example</h2>
<pre class="diff-id-2 diff-noncompliant">try {
  doSomethingElse();
} catch (ex) {  // Noncompliant
  throw ex;
}
</pre>
<h2>Compliant Solution</h2>
<pre class="diff-id-2 diff-compliant">try {
  doSomethingElse();
} catch (ex) {
  console.err(ex);
  throw ex;
}
</pre>