<?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[Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot;]]></title><description><![CDATA[<p>Ich experimentiere ein bisschen mit den Exceptions von c++.</p>
<p>Statt die Fehlermeldung anzuzeigen, die ich eigentlich wollte, stürzt das Programm ab und in der Konsole erscheint:</p>
<p>&quot;<br />
This application has requested the Runtime to terminate it in an unusual way.<br />
Please contact the application's support team for more information.&quot;</p>
<p>Kommt das jemandem bekannt vor? Was habe ich wahrscheinlich falsch gemacht?</p>
<p>Wenn ich die Zeile mit &quot;throw&quot; auskommentiere, wird das Programm normal beendet.</p>
<pre><code class="language-cpp">TiXmlDocument doc(pfad);
	doc.LoadFile();
	if (doc.Error()) {
		std::string pfadstr(pfad);
		std::cout &lt;&lt; &quot;error&quot; &lt;&lt;std::endl;
		throw std::logic_error(&quot;Menue-Datei \&quot;&quot;+pfadstr+&quot;\&quot; konnte nicht geoeffnet werden.&quot;);
	} else {
		TiXmlElement* root = doc.RootElement();
		// TODO ...
	}
</code></pre>
<p>Ich benutze Eclipse mit MinGW.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/223526/merkwürdige-quot-exception-ausgabe-quot</link><generator>RSS for Node</generator><lastBuildDate>Sat, 03 Oct 2026 19:18:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/223526.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 26 Sep 2008 21:09:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Fri, 26 Sep 2008 21:09:22 GMT]]></title><description><![CDATA[<p>Ich experimentiere ein bisschen mit den Exceptions von c++.</p>
<p>Statt die Fehlermeldung anzuzeigen, die ich eigentlich wollte, stürzt das Programm ab und in der Konsole erscheint:</p>
<p>&quot;<br />
This application has requested the Runtime to terminate it in an unusual way.<br />
Please contact the application's support team for more information.&quot;</p>
<p>Kommt das jemandem bekannt vor? Was habe ich wahrscheinlich falsch gemacht?</p>
<p>Wenn ich die Zeile mit &quot;throw&quot; auskommentiere, wird das Programm normal beendet.</p>
<pre><code class="language-cpp">TiXmlDocument doc(pfad);
	doc.LoadFile();
	if (doc.Error()) {
		std::string pfadstr(pfad);
		std::cout &lt;&lt; &quot;error&quot; &lt;&lt;std::endl;
		throw std::logic_error(&quot;Menue-Datei \&quot;&quot;+pfadstr+&quot;\&quot; konnte nicht geoeffnet werden.&quot;);
	} else {
		TiXmlElement* root = doc.RootElement();
		// TODO ...
	}
</code></pre>
<p>Ich benutze Eclipse mit MinGW.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1588714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1588714</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Fri, 26 Sep 2008 21:09:22 GMT</pubDate></item><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Fri, 26 Sep 2008 21:42:33 GMT]]></title><description><![CDATA[<p>Hast du das throw in einen try-Block eingeschlossen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1588731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1588731</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Fri, 26 Sep 2008 21:42:33 GMT</pubDate></item><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Fri, 26 Sep 2008 22:36:47 GMT]]></title><description><![CDATA[<p>Ich hab das throw nicht direkt in einem try-Block.<br />
Stattdessen ist die Stelle, wo der Konstruktor aufgerufen wird in einem Try-Block.</p>
<p>Nochmal die komplette Funktion:</p>
<pre><code>Menue::Menue() throw() {
	TiXmlDocument doc(pfad);
	doc.LoadFile();
	if (doc.Error()) {
		std::string pfadstr(pfad);
		std::cout &lt;&lt; &quot;error&quot; &lt;&lt;std::endl;
		throw std::logic_error(&quot;Menue-Datei \&quot;&quot;+pfadstr+&quot;\&quot; konnte nicht geoeffnet werden.&quot;);
	} else {
		TiXmlElement* root = doc.RootElement();
		// TODO ...
	}
}
</code></pre>
<p>&quot;pfad&quot; ist ein <em>static char</em>*</p>
<p>Wenn ich das try weglasse, passiert das selbe.</p>
<p>Noch was:<br />
Der Konstruktor wird nicht direkt aufgerufen, eigentlich wird eine Funktion aufgerufen, die ihrerseits eine Funktion, die in einem Funktionszeiger gespeichert ist aufruft, die eine Instanz von &quot;Menue&quot; zurückgibt. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /><br />
(Ich wollte eine Art erweiterbaren Automat machen.)<br />
Immerhin funktioniert es ja ohne das throw.</p>
<p>Brauch ich in den ganzen &quot;Kapselfunktionen&quot; auch throw()? Und wenn ja, brauch ich auch throw() in den Basisklassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1588744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1588744</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Fri, 26 Sep 2008 22:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Fri, 26 Sep 2008 22:38:59 GMT]]></title><description><![CDATA[<p>Du verletzt absichtlich Deine &quot;exception specification&quot; (s.a. google).</p>
<p>obbba schrieb:</p>
<blockquote>
<p>...</p>
<pre><code>Menue::Menue() throw() { // &lt;- hier sagst Du, dass diese Funktion keine Exception werfen soll
...
throw std::logic_error(&quot; // &lt;- hier tust Du's trotzdem...
</code></pre>
</blockquote>
<p>Da solche Vergehen in C++ (wenn überhaupt) erst zur Laufzeit ausgewertet werden, siehst Du das Verhalten, das auch zu erwarten war (die runtime ruft die Funktion unexpected() auf, die standardmäßig die Funktion terminate() aufruft)</p>
<p>ergo: Hat gar nichts mit try/catch zu tun.<br />
Lösung: Entweder auf das 1. oder auf das 2. throw verzichten<br />
... und bitte das nächste Mal C++-Tags verwenden.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1588752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1588752</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 26 Sep 2008 22:38:59 GMT</pubDate></item><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Sun, 28 Sep 2008 19:22:03 GMT]]></title><description><![CDATA[<p>ahhhhh</p>
<p>&quot;throw()&quot; bedeutet, dass alle exceptions, die ankommen &quot;weitergeworfen&quot; werden?</p>
<p>Auf jeden Fall funktionierts jetzt. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1589845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1589845</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Sun, 28 Sep 2008 19:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Sun, 28 Sep 2008 22:45:24 GMT]]></title><description><![CDATA[<p>obbba schrieb:</p>
<blockquote>
<p>ahhhhh</p>
<p>&quot;throw()&quot; bedeutet, dass alle exceptions, die ankommen &quot;weitergeworfen&quot; werden?<br />
...</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
Ich weiß nicht, woraus Du das jetzt schließt, aber throw hat (wie fast alles in C++) seine eigene Bedeutung, je nachdem, wo es steht:</p>
<pre><code class="language-cpp">void f() throw(std::exception) { //1.: f darf nur std::exceptions werfen (also auch &quot;Nachkommen)
   try {
      dosomething();
      throw std::runtime_error(&quot;schmeiß was&quot;); // 2. wirf eine neue runtime_error-exception
   }
   catch(...) {
      cout &lt;&lt; &quot;error\n&quot;;
      throw; // 3. Wirf weiter, was auch immer geflogen ist
   }
}
</code></pre>
<p>Ein Spezialfall von 1. ist, dass throws Argumentliste leer ist (&quot;throw()&quot;), was gleichbedeutend ist mit &quot;darf gar nichts werfen&quot;.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1589939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1589939</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Sun, 28 Sep 2008 22:45:24 GMT</pubDate></item><item><title><![CDATA[Reply to Merkwürdige &amp;quot;Exception-Ausgabe&amp;quot; on Mon, 29 Sep 2008 05:33:53 GMT]]></title><description><![CDATA[<p>obbba schrieb:</p>
<blockquote>
<p>ahhhhh</p>
<p>&quot;throw()&quot; bedeutet, dass alle exceptions, die ankommen &quot;weitergeworfen&quot; werden?</p>
</blockquote>
<p>Nein. Throw() im Funktionskopf bedeutet &quot;diese Funktion wirft keine Exception, das darfst du zur Laufzeit gerne nachprüfen&quot; - oder ums genau zu nehmen &quot;aus dieser Funktion wird nie eine Exception kommen&quot;, also dürfen auch darin aufgerufene weitere Funktionen keine Exceptions werfen (es sei denn sie stehen in einem try-Block und du verarbeitest diese weiteren Exceptions).<br />
Anders als in Java wird das aber nicht zur Compilezeit geprüft, ob da möglicherweise doch eine Exception entfleuchen könnte, deshalb hat dein Beispiel oben auch kompiliert.<br />
Du hast allerdings mutwillig gegen deine eigene Exception-Spezifikation verstoßen, und das mag das Programm garnicht: wenn eine Funktion mit Exceptionspezifikation aufgerufen wird, wird jede Exception die fliegt überprüft. Ist sie nicht in der Liste der &quot;erlaubten&quot; Exceptions (bei dir war diese Liste leer), dann wird die Funktion unexpected() aufgerufen. Was die macht ist Einstellugnssache, wenn nichts eingestellt worden ist (via set_unexpected()) wird terminate() aufgerufen. Was terminate() macht ist auch Einstellungssache (via set_terminate()) - aber wie der Name schon sagt beendet Terminate das Programm, standardmäßig wird abort() aufgerufen, wodurch das Programm sofort beendet wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1590010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1590010</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 29 Sep 2008 05:33:53 GMT</pubDate></item></channel></rss>