+ 5
catch(string& name) vs catch(string name)
i.ex.: i throw exception try{ throw int(123);} catch(int& obj) {cout<<"With &: "<<obj;} What is the difference betwen those two catch statments (what is the effect of using reference here?) catch(int obj) {cout<<"Without: "<<obj;} Both versions Of catch prints same output.
2 ответов
+ 2
In this case, there is no reason to catch int(123) by reference other than C++ coding conventions.
The original reason to why people usually catch by reference involves the thrown exceptions inheriting from a base exception class.
https://stackoverflow.com/questions/2522299/c-catch-blocks-catch-exception-by-value-or-reference
0
<redacted>
Дмитрий Кузьмин (xeoneon), просьба ознакомиться с данным руководством:
https://www.sololearn.com/discuss/1183249/?ref=app