Exception Handling Question

后端 未结 8 683
谎友^
谎友^ 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

    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

提交回复
热议问题