Why do Java people frequently consume exceptions silently?

前端 未结 28 1618
傲寒
傲寒 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 18:14

    I have always thought, that's similar to the following scenario:

    "A man gets shot.

    He holds his breath and has enough strength to take a bus.

    10 miles later the man gets off of the bus, walks a couple of blocks and dies."

    When the police gets to the body, they don't have a clue of what has just happened. They may have eventually but it is much harder.

    Better is:

    "A man gets shot and he dies instantly, and the body lies exactly where the murder just happened."

    When the police arrives, all the evidence is in place.

    If a system is to fail, better is to fail fast

    Addressing the question:

    1. Ignorance.
        +
    2. Sloth

    EDIT:

    Of course, the catch section is useful.

    If something can be done with the exception, that's where it should be done.

    Probably that is NOT an exception for the given code, probably it is something that is expected ( and in my analogy is like a bulletproof jacket, and the man was waiting for the shot in first place ).

    And yes, the catch could be used to Throw exceptions appropriate to the abstraction

提交回复
热议问题