6

My boss answered this question why ... (three points) in catch block is exist? quite elegantly.

But it's made me think of something (and hopefully makes up for my previous bad question), does

catch(...){
    throw;
}

rethrow the caught exception by value (i.e. a deep copy is taken), or by reference?

Community
  • 1
  • 1
P45 Imminent
  • 8,319
  • 4
  • 35
  • 78
  • 3
    _The re-thrown exception object is the original exception object, not a copy._ Taken from the Remarks in [try, throw and catch statements](https://msdn.microsoft.com/en-GB/library/6dekhbbc.aspx). So based on that, I assume by reference? โ€“ Jonathon Ogden Apr 20 '16 at 08:42
  • Possible duplicate of [do the default catch throw statements in C++ pass by value or reference](http://stackoverflow.com/questions/9562053/do-the-default-catch-throw-statements-in-c-pass-by-value-or-reference) โ€“ Captain Giraffe Apr 20 '16 at 08:50

1 Answers1

9

The standard says:

A throw-expression with no operand rethrows the currently handled exception. The exception is reactivated with the existing temporary; no new temporary exception object is created.

-- ISO/IEC 14882:2011 Section 15.1 par. 8

In other words, it simply continues the exception propagation with the original exception object. I suppose this is analogous to what you mean by "by reference".

Andrew
  • 5,212
  • 1
  • 22
  • 40
  • 1
    The location has changed in later drafts ยง5.17/3, but the wording and intent remain; [see here for a link](http://eel.is/c++draft/expr.throw#3). And this quote *"If a handler exits by rethrowing, control is passed to another handler for the same exception."* from [here](http://eel.is/c++draft/except#except.throw-4). โ€“ Niall Apr 20 '16 at 09:06