Exception handling try catch inside catch

前端 未结 3 1884
别跟我提以往
别跟我提以往 2020-12-13 17:59

I recently came across code written by a fellow programmer in which he had a try-catch statement inside a catch!

Please forgive my inability to paste the actual code

3条回答
  •  忘掉有多难
    2020-12-13 18:21

    Why is that bad? It's no different conceptually than:

    void TrySomething() {
       try {
    
    
       } catch (ArgumentException) {
            HandleTrySomethingFailure();
       }
    }
    
    void HandleTrySomethingFailure() {
        try {
    
        } catch (IndexOutOfRangeException) {
    
        }
    }
    

    Before you go over there and give him a piece of your brain (try the parietal lobe, it's particularly offensive) , what exactly are you going to say to him? How will you answer the proverbial "why?"

    What's even more ironic is that when the jitter inlines this code, it will look exactly like your example.

    -Oisin

提交回复
热议问题