P45 Imminent
P45 Imminent

Reputation: 8591

Does a throw in catch(...) throw by value or by reference

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?

Upvotes: 7

Views: 165

Answers (1)

Andrew
Andrew

Reputation: 5352

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".

Upvotes: 10

Related Questions