I have the following C ++ code
template <class E> class ExceptionWrapper { public: explicit ExceptionWrapper(const E& e): e(e) {} void throwException() { throw e; } private: E e; }; ... try { ExceptionWrapper<E> w(...); w.throwException(); } catch (const E& e) { ... } ...
Question: Is this code valid? I could argue that returning a reference to a class member is almost always invalid (and I'm sure everyone agrees with this statement). However, my colleague claims that this does not apply to throw .
PS after changing catch (const E& e) to catch (E e) unpleasant error seemed to disappear, which strengthened my position - this code is invalid.
c ++ reference exception
Solenodon Paradoxus Oct. 20 '15 at 16:30 2015-10-20 16:30
source share