<?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[Frage zu try&#x2F;catch]]></title><description><![CDATA[<pre><code>TStringList *list = new TStringList();
...
try
{
    list-&gt;SaveToFile(filename);
    delete list;
}
catch (...)
{
    delete list;
}
</code></pre>
<p>Steht &quot;delete list&quot; im try-Block richtig, wenn SaveToFile nicht ausgeführt werden kann? Oder sollte man das umformulieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/156777/frage-zu-try-catch</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 04:24:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/156777.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 Aug 2006 07:01:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu try&#x2F;catch on Sun, 20 Aug 2006 07:01:11 GMT]]></title><description><![CDATA[<pre><code>TStringList *list = new TStringList();
...
try
{
    list-&gt;SaveToFile(filename);
    delete list;
}
catch (...)
{
    delete list;
}
</code></pre>
<p>Steht &quot;delete list&quot; im try-Block richtig, wenn SaveToFile nicht ausgeführt werden kann? Oder sollte man das umformulieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1120705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1120705</guid><dc:creator><![CDATA[Ingo]]></dc:creator><pubDate>Sun, 20 Aug 2006 07:01:11 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu try&#x2F;catch on Sun, 20 Aug 2006 08:18:03 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>falsch ist das nicht, aber besser als</p>
<pre><code class="language-cpp">TStringList *list = new TStringList();
...
try
{
    list-&gt;SaveToFile(filename);
}
catch (...)
{
}
delete list;
</code></pre>
<p>ist es nicht.</p>
<p>Wenn du wirklich Exception-sicheren Code schreiben willst, sollte der so aussehen</p>
<pre><code class="language-cpp">#include &lt;memory&gt;
...
try
{
    // auto_ptr löscht automatisch das übergebene Objekt, sobald
    // der eigene Scope verlassen wird. Egal ob regulär oder durch Exception
    std::auto_ptr&lt;TStringList&gt; list(new TStringList());
    list-&gt;SaveToFile(filename);
}
catch (...)
{
}
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1120713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1120713</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sun, 20 Aug 2006 08:18:03 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu try&#x2F;catch on Sun, 20 Aug 2006 08:38:55 GMT]]></title><description><![CDATA[<p>Danke. Kann man außer try-catch noch auf eine andere Art feststellen, ob SaveToFile fehlerfrei ausgeführt wurde?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1120721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1120721</guid><dc:creator><![CDATA[Ingo]]></dc:creator><pubDate>Sun, 20 Aug 2006 08:38:55 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu try&#x2F;catch on Sun, 20 Aug 2006 08:54:40 GMT]]></title><description><![CDATA[<p>- Du prüfst nach mit FileExist, ob die Datei vorhanden ist</p>
<p>- Du rechnest vorher aus, wieviele Bytes geschrieben werden, und schaust dann nach der Dateigröße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1120726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1120726</guid><dc:creator><![CDATA[Christian411]]></dc:creator><pubDate>Sun, 20 Aug 2006 08:54:40 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu try&#x2F;catch on Mon, 21 Aug 2006 13:53:37 GMT]]></title><description><![CDATA[<p>Ja, danke. Ich hatte (wohl fälschlicherweise) die Hoffnung, dass SaveToFile einen Rückgabewert hat (bool oder so), der mir sagt, obs geklappt hat oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1121573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1121573</guid><dc:creator><![CDATA[Ingo]]></dc:creator><pubDate>Mon, 21 Aug 2006 13:53:37 GMT</pubDate></item></channel></rss>