c++ - Is there any reason to catch an exception by value? -
this question has answer here:
sutter , alexandrescu's coding standards tell us catch exceptions reference.
of course, blanket recommendations have occasional exceptions (no pun intended). there use cases catching exception value should preferred?
the advantage catching reference, besides obvious reasons of not requiring copyability or performing copy (potentially slicing one), can modify , continue processing throw;
.
if want modify object, yet continue exception processing throw;
on non-modified object, must make copy, , 1 way of doing catch value.
i think it's pretty contrived, though. catch const
reference followed explicit copy better express intent.
also note, throwing new c++11 nested_exception
nest thrown exception object, not object received value, within new exception. in such conditions conceivably keep own reference received exception, go stale unless received reference.
Comments
Post a Comment