Why catch an exception as reference-to-const?

后端 未结 5 1996
醉梦人生
醉梦人生 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:17

    are you going to modify the exception? if not, it may as well be const. same reason you SHOULD use const anywhere else (I say SHOULD because it doesn't really make that much difference on the surface, might help compilers, and also help coders use your code properly and not do stuff they shouldn't)

    exception handlers, may be platform specific, and may put exceptions in funny places because they aren't expecting them to change?

提交回复
热议问题