c++ - The parameter for the 'catch' -


this question has answer here:

i read "programming: principles , practice using c++" book (bjarne stroustrup). author writes:

catch (runtime_error e) 

but writes:

catch (runtime_error& e) 

as know, first variant creates copy of source, second uses link. or mistaken? not important "catch" in case?

i have expected of time, use:

catch ( runtime_error const& e ) 

the difference between catch value , catch reference same pass value , pass reference function parameter. important difference when catching reference, dynamic type can derived type, value result in slicing (because of copy).

also, if catch non-const reference, , modify exception object, rethrow, modified object propagate.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -