Exception Handling Question

后端 未结 8 647
谎友^
谎友^ 2020-12-13 02:30

I have a question regarding exception handling. Consider following Java code snippet.

        try{
            //code
        }catch(SubSubException subsube         


        
相关标签:
8条回答
  • 2020-12-13 03:07

    The second approach is less readable. In addition Pokemon exception handling is never the way to go even though your "clever" trick is to use the instanceof keyword. I am not poking fun or mocking you in anyway, but it is best to write code for humans to read and maintain, not for the computer.

    0 讨论(0)
  • 2020-12-13 03:07

    Considering the code in the first block tests the type of the exception, test for the base exception once (in the second bit of code you are testing for the base Exception twice in a way) and is less indented (thus less logic to grok), my thought is that the first one is far nicer, easier to understand etc.

    Disadvantages: - Harder to understand

    0 讨论(0)
提交回复
热议问题