Files
openide/java/java-impl/resources/inspectionDescriptions/UnnecessaryInitCause.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

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>