exception handling (std::ios_base::failure)

C

Chris Forone

hello group,

are there differences (run-time, ...) between the following two versions?

....
catch (std::ios_base::failure exception)
....

....
catch (const std::ios_base::failure& exception) // attend reference
....

if not, what version do you prefer? thanks a lot!

cheers, chris
 
E

Erik Wikström

hello group,

are there differences (run-time, ...) between the following two versions?

...
catch (std::ios_base::failure exception)
...

...
catch (const std::ios_base::failure& exception) // attend reference
...

Yes, the first version must create a copy of the failure object while
the second version uses the same object that was thrown. In some cases
this will not matter, but in others it will. If you do not know the
difference between passing by reference and passing by value you should
read up on it.
if not, what version do you prefer? thanks a lot!

The second version is the preferred one.
 
C

Chris Forone

Erik said:
Yes, the first version must create a copy of the failure object while
the second version uses the same object that was thrown. In some cases
this will not matter, but in others it will. If you do not know the
difference between passing by reference and passing by value you should
read up on it.


The second version is the preferred one.

thanks! cheers, chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top