+4

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.

8/21/2019 11:32:50 PM

Adam

2 Answers

New Answer

+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

Ебаные неруси