<?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[try, catch hat keine Wirkung?]]></title><description><![CDATA[<p>Hallo ich bastel gerade ein wenig mit try und catch, dazu habe ich kleines Beispiel Programm geschrieben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt; 

using namespace std;

int main()
{
	int iZahlen[] = {14, 11, 2, 47, 21 };

	try
	{
		cout &lt;&lt; iZahlen[6] &lt;&lt; endl;
	}
	catch(exception ex)
	{
		cout &lt;&lt; ex.what() &lt;&lt; endl;
	}

	return 0;
}
</code></pre>
<p>Wenn ich das jetzt ausführe stürzt das Programm ab und ich bekomme vom Compiler folgenden Fehler:</p>
<pre><code>Run-Time Check Failure #3 - The variable 'iZahlen' is being used without being initialized.
</code></pre>
<p>Aber müsste er nicht in den catch Block springen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/218229/try-catch-hat-keine-wirkung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 15:45:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/218229.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Jul 2008 16:00:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 16:00:56 GMT]]></title><description><![CDATA[<p>Hallo ich bastel gerade ein wenig mit try und catch, dazu habe ich kleines Beispiel Programm geschrieben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt; 

using namespace std;

int main()
{
	int iZahlen[] = {14, 11, 2, 47, 21 };

	try
	{
		cout &lt;&lt; iZahlen[6] &lt;&lt; endl;
	}
	catch(exception ex)
	{
		cout &lt;&lt; ex.what() &lt;&lt; endl;
	}

	return 0;
}
</code></pre>
<p>Wenn ich das jetzt ausführe stürzt das Programm ab und ich bekomme vom Compiler folgenden Fehler:</p>
<pre><code>Run-Time Check Failure #3 - The variable 'iZahlen' is being used without being initialized.
</code></pre>
<p>Aber müsste er nicht in den catch Block springen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548946</guid><dc:creator><![CDATA[lord_fritte]]></dc:creator><pubDate>Thu, 17 Jul 2008 16:00:56 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 16:02:41 GMT]]></title><description><![CDATA[<p>ne, das was da geworfen wird ist keine exception. Das ist nur eine Debug-message. im release-modus stürzts einfach so ab oder gibt müll aus. Wenn du das ganze als vektor machst und <a href="http://iZahlen.at" rel="nofollow">iZahlen.at</a>(6) aufrufst, sollte aber eine exception geworfen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548950</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Thu, 17 Jul 2008 16:02:41 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 16:11:39 GMT]]></title><description><![CDATA[<p>Achso, danke.<br />
Aber gibt es keine Möglichkeit auch bei einem Array eine Exception werfen zu lassen?</p>
<p>Aber bei einem Vector bekomme ich:<br />
Unknown exception ich finde eine sehr aussagekräftige Meldung ist das..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548954</guid><dc:creator><![CDATA[lord_fritte]]></dc:creator><pubDate>Thu, 17 Jul 2008 16:11:39 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 16:24:59 GMT]]></title><description><![CDATA[<p>vector wirft nur eine Exception, wenn du mit der Methode at auf die Elemente zugreifst:</p>
<pre><code class="language-cpp">vector&lt;int&gt; v(10);
...
int i = v.at(20) // =&gt; std::out_of_range oder wie die heißt, sowas benutzt eigentlich niemand ;)
</code></pre>
<p>Zugriffe über Array-Grenzen hinweg (oder beim Vector mit dem [] Operator) erzeugen einfach undefiniertes Verhalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548957</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 17 Jul 2008 16:24:59 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 16:25:30 GMT]]></title><description><![CDATA[<p>lord_fritte schrieb:</p>
<blockquote>
<p>Aber gibt es keine Möglichkeit auch bei einem Array eine Exception werfen zu lassen?</p>
</blockquote>
<p>Nein, weil ein Array keine Grössenangaben über sich selber kennt. Das Array ist eigentlich nur ein Speicherblock und mehr nicht. Deshalb muss man sich eigene Konstrukte dazu bauen oder die Standardcontainer verwenden.</p>
<p>lord_fritte schrieb:</p>
<blockquote>
<p>Aber bei einem Vector bekomme ich:<br />
Unknown exception ich finde eine sehr aussagekräftige Meldung ist das..</p>
</blockquote>
<p>Bei mir (MSVC 2005) ist die Fehlermeldung auch nicht viel besser:<br />
&quot;invalid vector&lt;T&gt; subscript&quot;</p>
<p>Allerdings kann man sich da etwas Abhilfe schaffen:</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; MyVector;

for(int i = 0; i &lt; 10; ++i)
{ MyVector.push_back(i); }

try
{ MyVector.at(11); }
catch(std::out_of_range&amp; rException) // &lt;- Das ist die eigentliche Exception, welche fliegt.
{ std::cout &lt;&lt; &quot;Out of range!&quot; &lt;&lt; std::endl; } // &lt;- Eigene Fehlermeldung ausgeben.
catch(...)
{ std::cout &lt;&lt; &quot;Unknown exception!&quot; &lt;&lt; std::endl; }
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548958</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 17 Jul 2008 16:25:30 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 17:12:31 GMT]]></title><description><![CDATA[<p>Dravere schrieb:</p>
<blockquote>
<p>Bei mir (MSVC 2005) ist die Fehlermeldung auch nicht viel besser:<br />
&quot;invalid vector&lt;T&gt; subscript&quot;</p>
</blockquote>
<p>Was hättest Du denn gern? Die Meldung sagt doch alles.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548984</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 17 Jul 2008 17:12:31 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 17:20:25 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>Dravere schrieb:</p>
<blockquote>
<p>Bei mir (MSVC 2005) ist die Fehlermeldung auch nicht viel besser:<br />
&quot;invalid vector&lt;T&gt; subscript&quot;</p>
</blockquote>
<p>Was hättest Du denn gern? Die Meldung sagt doch alles.</p>
</blockquote>
<p>Hast du ein Smilie vergessen? Zum Beispiel so eins -&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /><br />
Wenn nicht und du das wirklich ernst meinst, dann muss ich dir zustimmen, die Meldung sagt wirklich alles. Es könnte x-beliebig was passiert sein. Ein Unknown error wäre genau so gut :p</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1548990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1548990</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 17 Jul 2008 17:20:25 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 17:57:20 GMT]]></title><description><![CDATA[<p>&quot;Ungültiger Vektorindex&quot;. Stimmt, wie kann man das nur verstehen? Da sollte stehen: &quot;Hallo lieber Programmierer, es sieht so aus als hätten Sie versucht auf ein Vektorelement zuzugreifen, das nicht existiert. Soll ich (1) den Vektor entsprechend vergrößern, (2) den Vorgang an Microsoft melden?&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549001</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 17 Jul 2008 17:57:20 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 18:08:44 GMT]]></title><description><![CDATA[<p>Ach du Schande ... Tja, jetzt erkenn ich den Fehler, mein Englisch weisst Lücken auf.<br />
Subscript heisst Index? Ein Index ist für mich immer noch ein Index, auch im Englischen. Während ein subscript für mich eher ein Script innerhalb eines anderen Scripts ist. Daher verstand ich die Fehlermeldung eher als &quot;Fehler im Code!&quot;, was nichtsaussagend wäre.</p>
<p>Aber man lernt nie aus, danke für die Nachhilfe ^^</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549008</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 17 Jul 2008 18:08:44 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 18:11:46 GMT]]></title><description><![CDATA[<p>Sub\1: A<sub>n</sub> (im Deutschen heißt das Index)<br />
Super\1: A<sup>n</sup></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549009</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549009</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 17 Jul 2008 18:11:46 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 18:21:49 GMT]]></title><description><![CDATA[<p>Kann man mit C++09 den Fehler von ganz oben abfangen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549015</guid><dc:creator><![CDATA[danextc++]]></dc:creator><pubDate>Thu, 17 Jul 2008 18:21:49 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 18:33:42 GMT]]></title><description><![CDATA[<p>Ich hatte ernsthaft überlegt, wie man die Meldung detaillierter gestalten hätte können - Erwähnung des Index, des Typs, der Methode? Schade, dass es sich nur um ein sprachliches Missverständnis gehandelt hat, denn ich hätte zu allen Gegenargumente gefunden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Zum Sprachlichen gebe ich aber zu, dass sich mir als COBOL-Vorbelasteter &quot;subscript out of range&quot; bereits mehr oder weniger ins Hirn eingebrannt hat. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549026</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 17 Jul 2008 18:33:42 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Thu, 17 Jul 2008 21:58:26 GMT]]></title><description><![CDATA[<p>danextc++ schrieb:</p>
<blockquote>
<p>Kann man mit C++09 den Fehler von ganz oben abfangen?</p>
</blockquote>
<p>nein. das man das nicht kann und das ist eine bewusste entscheidung. der operator[] soll ein low-level-operator sein, der von der geschwindigkeit her dem aus c gleichwertig sein soll, daher kann man keine bereichsprüfung direkt einbauen und folglich auch nichts werfen. wenn du sicherheit haben willst, benutze die schon erwähnten at()-funktion, dafür gibt es sie.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549088</guid><dc:creator><![CDATA[ghorst]]></dc:creator><pubDate>Thu, 17 Jul 2008 21:58:26 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Fri, 18 Jul 2008 06:28:09 GMT]]></title><description><![CDATA[<p>ghorst schrieb:</p>
<blockquote>
<p>danextc++ schrieb:</p>
<blockquote>
<p>Kann man mit C++09 den Fehler von ganz oben abfangen?</p>
</blockquote>
<p>nein. das man das nicht kann und das ist eine bewusste entscheidung. der operator[] soll ein low-level-operator sein, der von der geschwindigkeit her dem aus c gleichwertig sein soll, daher kann man keine bereichsprüfung direkt einbauen und folglich auch nichts werfen. wenn du sicherheit haben willst, benutze die schon erwähnten at()-funktion, dafür gibt es sie.</p>
</blockquote>
<p>Nein, stimmt nicht ganz. Der []-Operator muß keine, aber darf eine Bereichsprüfung vornehmen! Benutze mal MSVC2005 und neuer, dort wird genau das gemacht: die []-Operatoren und Iteratoren machen standardmäßig eine Gültigkeitsprüfung (gehört zur neuer MS-Sicherheitstrategie). Wer das nicht will, muß es explizit abschalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549139</guid><dc:creator><![CDATA[Schneeflocke]]></dc:creator><pubDate>Fri, 18 Jul 2008 06:28:09 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Fri, 18 Jul 2008 08:43:15 GMT]]></title><description><![CDATA[<p>Schneeflocke schrieb:</p>
<blockquote>
<p>Nein, stimmt nicht ganz. Der []-Operator muß keine, aber darf eine Bereichsprüfung vornehmen!</p>
</blockquote>
<p>Es dürfen auch Dämonen aus der Nase fliegen. Das ist eben <strong>undefiniertes</strong> Verhalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1549216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1549216</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Fri, 18 Jul 2008 08:43:15 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Sun, 24 Aug 2008 23:59:15 GMT]]></title><description><![CDATA[<p><div class="plugin-markdown"><input type="checkbox" id="checkbox70889" checked="true" /><label for="checkbox70889">drauf zugreife, scheint der ganze catch Mist ja wieder ausgehebelt zu sein...</label></div></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570746</guid><dc:creator><![CDATA[lord_fritte]]></dc:creator><pubDate>Sun, 24 Aug 2008 23:59:15 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Mon, 25 Aug 2008 06:49:44 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>nur, weils noch keiner geschrieben hat:</p>
<p>lord_fritte schrieb:</p>
<blockquote>
<pre><code class="language-cpp">...	catch(exception ex)
...
</code></pre>
</blockquote>
<p>Es gibt verschiedene Gründe, warum man Exceptions besser per Referenz fangen sollte:</p>
<pre><code class="language-cpp">...	catch(exception&amp; ex)
...
</code></pre>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570789</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 25 Aug 2008 06:49:44 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Mon, 25 Aug 2008 06:51:54 GMT]]></title><description><![CDATA[<p>lord_fritte schrieb:</p>
<blockquote>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox70890" checked="true" /><label for="checkbox70890">drauf zugreife, scheint der ganze catch Mist ja wieder ausgehebelt zu sein...</label></div></p>
</blockquote>
<p>Ja, und das ist auch Sinn der Sache.</p>
<p>Wenn dein Code so wackelig ist, dass du per Default eine Bereichsprüfung brauchst, dann nimm halt std::vector::at.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570790</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 25 Aug 2008 06:51:54 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Mon, 25 Aug 2008 07:06:04 GMT]]></title><description><![CDATA[<p>MFK schrieb:</p>
<blockquote>
<p>Wenn dein Code so wackelig ist, dass du per Default eine Bereichsprüfung brauchst, dann nimm halt std::vector::at.</p>
</blockquote>
<p>Oder lass es noch besser garnicht erst zur Exception kommen sondern frage size() ab und schau ob der Index auf den du zugreifen willst existiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570801</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570801</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 25 Aug 2008 07:06:04 GMT</pubDate></item><item><title><![CDATA[Reply to try, catch hat keine Wirkung? on Mon, 25 Aug 2008 07:16:29 GMT]]></title><description><![CDATA[<p>lord_fritte schrieb:</p>
<blockquote>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox70891" checked="true" /><label for="checkbox70891">drauf zugreife, scheint der ganze catch Mist ja wieder ausgehebelt zu sein...</label></div></p>
</blockquote>
<p>Nein - es ist halt nur so, dass man in seinem Programm auch Fehler machen kann, die nicht mittels try/catch erkennbar sind (z.B. bewusst einen &quot;prüfungsfreien&quot; operator[] zu verwenden).<br />
Irgendwie geht halt nicht Beides: Keine Prüfung haben zu wollen UND gleichzeitig doch vor den eigenen Programmierfehlern geschützt zu sein.<br />
(OK, für triviale Programme mag das möglich sein)</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570811</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 25 Aug 2008 07:16:29 GMT</pubDate></item></channel></rss>