<div dir="auto"><div>Thanks Manu. I do have a few ways around this, but I like your idea the best.<div dir="auto"><br></div><div dir="auto">Still, I think this problem is significant enough and common enough that we are justified by putting it in the compiler warning list.</div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Jun 20, 2025, 9:50 PM Manu Sridharan <<a href="mailto:manu@sridharan.net">manu@sridharan.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="ltr">
Hi David, FYI Error Prone has a check for this:</div><div dir="ltr"><br></div><div dir="ltr"><a href="https://errorprone.info/bugpattern/EmptyCatch" target="_blank" rel="noreferrer">https://errorprone.info/bugpattern/EmptyCatch</a><br></div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr">Best,</div>Manu </div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Jun 21, 2025 at 08:18:25, David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank" rel="noreferrer">davidalayachew@gmail.com</a>> wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" type="cite">
<div dir="auto"><div>Oh I agree they serve a purpose. But I think the default is on the wrong side. I think it should warn by default, and let me supress warnings if it indeed is intentional. That's why I am suggesting this compiler warning -- to allow me to opt-in to switching the default.</div><div dir="auto"><br></div><div dir="auto">I was not the one who wrote the empty catches. But I am finding that each one was a mistake of some sort. For almost every one, we could have logged it at least. Leaving them empty was wrong in almost every single instance I found.</div><div dir="auto"><br></div><div dir="auto">And the folks who committed most of these were intern-level devs -- devs who don't know the difference between static and instance.</div><div dir="auto"><br></div><div dir="auto">Now that I am playing clean up, I wanted to make it easier to just bring all these (likely) problematic empty catch blocks to the surface, then put a SuppressWarnings on each one that actually SHOULD be empty (yet to find one, but I concede that is possible).<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Fri, Jun 20, 2025, 7:11 PM Chen Liang <<a href="mailto:chen.l.liang@oracle.com" target="_blank" rel="noreferrer">chen.l.liang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Empty catch blocks serve a purpose: They aim to catch the type of exception from the try block, and continue execution from immediately after the try-catch statement. As Brian Goetz often says, let's first look at the problem instead of a solution. What prompted
you to write those empty catch blocks at first?</div>
<div id="m_2774223500513480836m_8658320473311857897appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_2774223500513480836m_8658320473311857897divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> compiler-dev <<a href="mailto:compiler-dev-retn@openjdk.org" rel="noreferrer noreferrer" target="_blank">compiler-dev-retn@openjdk.org</a>> on behalf of David Alayachew <<a href="mailto:davidalayachew@gmail.com" rel="noreferrer noreferrer" target="_blank">davidalayachew@gmail.com</a>><br>
<b>Sent:</b> Friday, June 20, 2025 6:00 PM<br>
<b>To:</b> compiler-dev <<a href="mailto:compiler-dev@openjdk.org" rel="noreferrer noreferrer" target="_blank">compiler-dev@openjdk.org</a>><br>
<b>Subject:</b> Can we get compiler warnings for empty catch blocks?</font>
<div> </div>
</div>
<div>
<div dir="auto">I got burned pretty bad today because of a large number of empty catch blocks.
<div dir="auto"><br>
</div>
<div dir="auto">If a compiler warning is not feasible or not a good idea, that's fine.</div>
<div dir="auto"><br>
</div>
<div dir="auto">But please let me know -- whether yes, no, or otherwise.</div>
</div>
</div>
</div>
</blockquote></div></div></div>
</blockquote>
</div></div>
</blockquote></div></div></div>