+ 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.

21st Aug 2019, 11:32 PM
Adam
2 Respuestas
+ 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
22nd Aug 2019, 12:06 AM
Hatsy Rei
Hatsy Rei - avatar
0
<redacted> Дмитрий Кузьмин (xeoneon), просьба ознакомиться с данным руководством: https://www.sololearn.com/discuss/1183249/?ref=app
1st Sep 2019, 1:05 PM
Дмитрий Кузьмин (xeoneon)