2

I see tons of throws XExc, YExc, ZExc or throws Exception or catch XExc, YExc, ZExc or cacth Exception proliferating java code. C# was nice as this exception proliferation does not occur.

In fact throw and catch Exception is unhelpful and it mine as well be just runtimeException. The list of 12 exceptions is really no better since some are like IOException and we have no idea what is really in that until Runtime. then on top of that implementations like StringReader look like they throw and you have to catch an Exception that can never happen.

Lastly, exceptions end up being wrapped causing issues on not being able to catch the right exception. This is probably the biggest smell and some may argue no one should wrap. instead I would like to see if I could compile without checked exceptions in java.

We have tons of code like

    try {
        return getSelectorManager().registerChannelForRead(this, dataListener).thenApply(v -> {
            isRegisterdForReads = true;
            return this;
        });
    } catch (IOException e) {
        throw new NioException(e);
    } catch (InterruptedException e) {
        throw new NioException(e);
    }

I also wonder if that would work as binary compatibility would be weird as an IOException cannot be caught without turning that same option on so only client who set the same option would work.

Dean Hiller
  • 19,235
  • 25
  • 129
  • 212

0 Answers0