Performance Considerations for throwing Exceptions

前端 未结 8 1118
旧时难觅i
旧时难觅i 2020-12-19 03:17

I have come across the following type of code many a times, and I wonder if this is a good practice (from Performance perspective) or not:

try
{
    ... // s         


        
8条回答
  •  眼角桃花
    2020-12-19 04:22

    From a purely performance stand-point I'd guess that the third case is most performant. The other two need to extract a stack-trace and construct new objects, both of which are potentially fairly time-consuming.

    Having said that these three blocks of code have very different (external) behaviors so comparing them is like asking whether QuickSort is more efficient than Adding an item to a red-black tree. It's not as important as selecting the right thing to do.

提交回复
热议问题