mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
28 lines
921 B
HTML
28 lines
921 B
HTML
<html>
|
|
<body>
|
|
Reports calls to <code>Throwable.initCause()</code> where an exception constructor also takes a <code>Throwable cause</code> argument.
|
|
<p>In this case, the <code>initCause()</code> call can be removed and its argument can be added to the call to the exception's constructor.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
try {
|
|
process();
|
|
}
|
|
catch (RuntimeException ex) {
|
|
RuntimeException wrapper = new RuntimeException("Error while processing");
|
|
wrapper.initCause(ex); // Unnecessary call to 'Throwable.initCause()'
|
|
throw wrapper;
|
|
}
|
|
</code></pre>
|
|
<p>A quick-fix is available to pass the cause argument to the constructor. After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
try {
|
|
process();
|
|
}
|
|
catch (RuntimeException ex) {
|
|
RuntimeException wrapper = new RuntimeException("Error while processing", ex);
|
|
throw wrapper;
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
</body>
|
|
</html> |