Why are try blocks expensive?

前端 未结 11 2454
醉酒成梦
醉酒成梦 2020-12-02 13:13

I\'ve heard the advice that you should avoid try catch blocks if possible since they\'re expensive.

My question is specifically about the .NET platform: Why are try

11条回答
  •  悲哀的现实
    2020-12-02 13:52

    I doubt if they are particularly expensive. A lot of times, they are necessary/required.

    Though I strongly recommend using them only when necessary and at the right places / level of nesting instead of rethrowing the exception at every call return.

    I would imagine the main reason for the advice was to say that you shouldnt be using try-catches where if---else would be a better approach.

提交回复
热议问题