Why catch an exception as reference-to-const?

后端 未结 5 1995
醉梦人生
醉梦人生 2020-11-27 15:07

I\'ve heard and read many times that it is better to catch an exception as reference-to-const rather than as reference. Why is:

try {
    // stuff
} catch (c         


        
5条回答
  •  无人及你
    2020-11-27 15:32

    It tells the compiler that you won't be calling any function which modify the exception, which may help to optimize the code. Probably doesn't make much of a difference, but the cost of doing it is very small too.

提交回复
热议问题