TITLE: where do exceptions live (Newsgroups: comp.lang.c++.moderated, 1 May 97) SUTTER: herbs@cntc.com (Herb Sutter) An email response to this solution asked: >Where does a thrown exception live? I can't seem to make it >fit in any of these places. Answer: It's a temporary, and where in memory it lives is specifically unspecified. From 15.1 [except.throw], especially the first sentence of paragraph 4: 3 A throw-expression initializes a temporary object, the type of which is determined by removing any top-level cv-qualifiers from the static type of the operand of throw and adjusting the type from "array of T" or "function returning T" to "pointer to T" or "pointer to function returning T", respectively. The temporary is used to initialize the variable named in the matching handler (_except.handle_). The type of the throw-expression shall not be an incomplete type, or a pointer or reference to an incomplete type, other than void*, const void*, volatile void*, or const volatile void*. Except for these restric- tions and the restrictions on type matching mentioned in _except.han- dle_, the operand of throw is treated exactly as a function argument in a call (_expr.call_) or the operand of a return statement. >4 The memory for the temporary copy of the exception being thrown is > allocated in an unspecified way, except as noted in _basic.stc.dynamic.allocation_. The temporary persists as long as there is a handler being executed for that exception. In particular, if a handler exits by executing a throw; statement, that passes con- trol to another handler for the same exception, so the temporary remains. If the use of the temporary object can be eliminated without changing the meaning of the program except for the execution of con- structors and destructors associated with the use of the temporary object (_class.temporary_), then the exception in the handler can be initialized directly with the argument of the throw expression. When the thrown object is a class object, and the copy constructor used to initialize the temporary copy is not accessible, the program is ill- formed (even when the temporary object could otherwise be eliminated). Similarly, if the destructor for that object is not accessible, the program is ill-formed (even when the temporary object could otherwise be eliminated).