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

后端 未结 8 862
余生分开走
余生分开走 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:42

    Exceptions as its name implies are intended to be exceptional. Hence you can't expect them to have been an important target for optimisation. More often then not they don't perform well since they have other priorites such as gathering detailed info about what went wrong.

    0 讨论(0)
  • 2021-01-13 02:43

    running code through a try/catch statement does not affect performance at all. The only performance hit comes if an exception is thrown ... because then the runtime has to unwind the stack and gather other information in order to populate the exception object.

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