<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Exceptions per Referenz fangen]]></title><description><![CDATA[<p>Warum ist es erlaubt, eine Exception per Referenz zu fangen? Wenn ich &quot;throw 42;&quot; schreibe, werfe ich ja einen RValue. Trotzdem kann ich hier mit int&amp; fangen? Wird die Exception irgendwo zwischengespeichert, oder warum ist das erlaubt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/289651/exceptions-per-referenz-fangen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 00:58:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/289651.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Jul 2011 11:46:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Exceptions per Referenz fangen on Sun, 10 Jul 2011 11:46:43 GMT]]></title><description><![CDATA[<p>Warum ist es erlaubt, eine Exception per Referenz zu fangen? Wenn ich &quot;throw 42;&quot; schreibe, werfe ich ja einen RValue. Trotzdem kann ich hier mit int&amp; fangen? Wird die Exception irgendwo zwischengespeichert, oder warum ist das erlaubt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2090921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2090921</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 10 Jul 2011 11:46:43 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions per Referenz fangen on Sun, 10 Jul 2011 12:06:23 GMT]]></title><description><![CDATA[<p>C++-Standard, §15.2 schrieb:</p>
<blockquote>
<p>When an exception is thrown, control is transferred to the nearest handler with a matching type (15.3); “nearest” means<br />
the handler for which the compound-statement, ctor-initializer, or function-body following the try keyword was most<br />
recently entered by the thread of control and not yet exited.<br />
<strong>A throw-expression initializes a temporary object, called the exception object</strong>, the type of which is determined by re-<br />
moving any top-level cv-qualifiers from the static type of the operand of throw and adjusting the type from “array of T”<br />
or “function returning T” to “pointer to T” or “pointer to function returning T”, respectively. [ Note: the temporary object<br />
created for a throw-expression that is a string literal is never of type char* or wchar_t*; that is, the special conversions<br />
for string literals from the types “array of const char” and “array of const wchar_t” to the types “pointer to char”<br />
and “pointer to wchar_t”, respectively (4.2), are never applied to a throw-expression. — end note ] <strong>The temporary is<br />
an lvalue and is used to initialize the variable named in the matching handler</strong> (15.3). The type of the throw-expression<br />
shall not be an incomplete type, or a pointer to an incomplete type other than (possibly cv-qualified) void. Except for<br />
these restrictions and the restrictions on type matching mentioned in 15.3, the operand of throw is treated exactly as a<br />
function argument in a call (5.2.2) or the operand of a return statement.<br />
The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in<br />
The temporary persists as long as there is a handler being executed for that exception. In particular, if a handler<br />
exits by executing a throw; statement, that passes control to another handler for the same exception, so the temporary<br />
remains. When the last remaining active handler for the exception exits by any means other than throw; the temporary<br />
object is destroyed and the implementation may deallocate the memory for the temporary object; any such deallocation<br />
is done in an unspecified way. The destruction occurs immediately after the destruction of the object declared in the<br />
exception-declaration in the handler.<br />
If the use of the temporary object can be eliminated without changing the meaning of the program except for the<br />
execution of constructors and destructors associated with the use of the temporary object (12.2), then the exception in<br />
the handler can be initialized directly with the argument of the throw expression. When the thrown object is a class<br />
object, and the copy constructor used to initialize the temporary copy is not accessible, the program is ill-formed (even<br />
when the temporary object could otherwise be eliminated). Similarly, if the destructor for that object is not accessible,<br />
the program is ill-formed (even when the temporary object could otherwise be eliminated).</p>
</blockquote>
<p>Interessante Stellen von mir hervorgehoben.</p>
<p>Entschuldigung für die schlechte Formatierung, so sieht das eben aus, wenn man aus einem formatierten pdf-Sokument kopiert und die Formatierungen nicht von Hand zeilenweise entfernen mag.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2090930</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2090930</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 10 Jul 2011 12:06:23 GMT</pubDate></item></channel></rss>