Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[wtp-releng] My Pet Peeve of the week: catch (Throwable


Some of you may have noticed me changing your code again.

This was to fix at least some of our dangerous exception handling.

We have HUNDREDS of places where we "catch (Throwable t)"
and 1) either do nothing with it ... the worst mistake or 2) simply log as some error and continue.
We should do neither.

There are a few cases where it might be legitimate to catch a Throwable ..
one easy rule of thumb, if you do not re-throw a Throwable, you should not be
catching it.

Most of our mis-uses can easily and safely be changed to "catch (Exception t)"
and achieve the original intent (This is a bad enough practice the way we blindly over use it, but
it is not as bad as catch Throwable).

The danger of catching throwable is that serious vm conditions are missed, and usually
surface later as some seemingly unpredictable error that can not be reproduced.

An Out of Memory Error is the most common of these.

Another common, critical one is "ThreadDeath". If those are caught and
not allowed to "surface", then threads will not be correctly ended.

So, ... I've done several hundred, but several hundred remain ...
please fix up any blind "catch Throwable" uses in your components.
Then we'll start on the blind "catch Exceptions" which are ignored :)

Just thought I'd explain.

Thanks,

Back to the top