Can we get compiler warnings for empty catch blocks?
David Alayachew
davidalayachew at gmail.com
Fri Jun 20 23:18:25 UTC 2025
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.
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.
And the folks who committed most of these were intern-level devs -- devs
who don't know the difference between static and instance.
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).
On Fri, Jun 20, 2025, 7:11 PM Chen Liang <chen.l.liang at oracle.com> wrote:
> 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?
> ------------------------------
> *From:* compiler-dev <compiler-dev-retn at openjdk.org> on behalf of David
> Alayachew <davidalayachew at gmail.com>
> *Sent:* Friday, June 20, 2025 6:00 PM
> *To:* compiler-dev <compiler-dev at openjdk.org>
> *Subject:* Can we get compiler warnings for empty catch blocks?
>
> I got burned pretty bad today because of a large number of empty catch
> blocks.
>
> If a compiler warning is not feasible or not a good idea, that's fine.
>
> But please let me know -- whether yes, no, or otherwise.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250620/fa241fd7/attachment.htm>
More information about the compiler-dev
mailing list