Why do Java people frequently consume exceptions silently?

前端 未结 28 1683
傲寒
傲寒 2020-11-29 17:50

I never did any serious Java coding before, but I learned the syntax, libraries, and concepts based on my existing skills (Delphi & C#). One thing I hardly understand i

28条回答
  •  长情又很酷
    2020-11-29 17:53

    I'm afraid that most of java programmers do not know what to do with Exceptions, and quite always consider it as an annoyance that slows their coding of the "nominal" case. Of course they're totally wrong, but it's difficult to convince them that IT IS important to correctly deal with exceptions. Every time I encounter such a programmer (it happens frequently) I give him two reading entries :

    • the famous Thinking In java
    • A short and interesting article of Barry Ruzek available here : www.oracle.com/technology/pub/articles/dev2arch/2006/11/effective-exceptions.html

    By the way, I strongly agree that it is stupid to catch a typed exception to rethrow it embedded in a RuntimeException :

    • if you catch it, HANDLE it.
    • otherwise, change your method signature to add possible exceptions that you would / could not handle, so your caller would have a chance to do it on his own.

提交回复
热议问题