Using Exceptions throwing in C#. Does it affect a performance?

后端 未结 8 863
余生分开走
余生分开走 2021-01-13 01:58

Basically, the question is: Do the Exceptions in C# affect the performance a lot? Is it better to avoid Exceptions rethrow? If i generate an exception in my code, does it a

8条回答
  •  走了就别回头了
    2021-01-13 02:29

    Raising an exception is an expensive operation in C# (compared to other operations in C#) but not enough that I would avoid doing it.

    I agree with Jared, if your application is significantly slower because of raising and throwing exceptions, I would take a look at your overall strategy. Something can probably be refactored to make exception handling more efficient rather than dismissing the concept of raising exceptions in code.

提交回复
热议问题