<?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[Execption &#x2F; Rückgabewert]]></title><description><![CDATA[<p>Hallo alle zusammen,</p>
<p>folgender Code:</p>
<pre><code class="language-cpp">Rechnung toread;
 try
        {
          fstream file(rechnrtodatname(rechnr), ios::in|ios::binary);
          if(file.is_open())
                file.write((const char*)&amp;toread,sizeof(toread));
          if(file.bad())
                throw &quot;Fehler beim lesen der Datei&quot;;
          return(toread);
        }
 catch(...)
        {

        }
</code></pre>
<p>Ich würde gern in den Catch(...) Body sowas wie ein return(NULL) schreiben.<br />
Leider erwartet er einen Rückgabewert vom Typ Rechnung. Wenn aber was schief geht darf ich kein ungültiges Objekt zurückgeben. Vorschläge?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/157757/execption-rückgabewert</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 12:40:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/157757.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 29 Aug 2006 10:03:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 10:03:41 GMT]]></title><description><![CDATA[<p>Hallo alle zusammen,</p>
<p>folgender Code:</p>
<pre><code class="language-cpp">Rechnung toread;
 try
        {
          fstream file(rechnrtodatname(rechnr), ios::in|ios::binary);
          if(file.is_open())
                file.write((const char*)&amp;toread,sizeof(toread));
          if(file.bad())
                throw &quot;Fehler beim lesen der Datei&quot;;
          return(toread);
        }
 catch(...)
        {

        }
</code></pre>
<p>Ich würde gern in den Catch(...) Body sowas wie ein return(NULL) schreiben.<br />
Leider erwartet er einen Rückgabewert vom Typ Rechnung. Wenn aber was schief geht darf ich kein ungültiges Objekt zurückgeben. Vorschläge?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1126708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126708</guid><dc:creator><![CDATA[Croatiancow]]></dc:creator><pubDate>Tue, 29 Aug 2006 10:03:41 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 10:37:20 GMT]]></title><description><![CDATA[<p>wer erwartet einen rückgabewert vom typ rechnung?<br />
der catch-block? wieso?</p>
<p>oder gibt diese funktion eine rehcnung zurück?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1126733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126733</guid><dc:creator><![CDATA[ser1al]]></dc:creator><pubDate>Tue, 29 Aug 2006 10:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 10:38:57 GMT]]></title><description><![CDATA[<p>Entschuldige.<br />
Mein Fehler.</p>
<p>Die Funktion gibt ein Objekt von Typ &quot;Rechnung&quot; zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1126734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126734</guid><dc:creator><![CDATA[Croatiancow]]></dc:creator><pubDate>Tue, 29 Aug 2006 10:38:57 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 10:59:12 GMT]]></title><description><![CDATA[<p>dann wirf doch die exception durch:</p>
<pre><code class="language-cpp">//im Catch-Block der Funktion

throw //irgendwas, text, zahl

//und wo die funktion verwendet wird:

Rechnung myRe;
try
{
 myRe = DeineFunktion();
}
catch(//das was du eben wirfst)
{
  //deine Behandlungsroutine
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1126747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126747</guid><dc:creator><![CDATA[ser1al]]></dc:creator><pubDate>Tue, 29 Aug 2006 10:59:12 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 11:44:42 GMT]]></title><description><![CDATA[<p>Hier der ganze code.</p>
<pre><code class="language-cpp">Rechnung open_bill(unsigned int rechnr)
{
 Rechnung toread;
 try
        {
          char datname[15];
          rechnrtodatname(rechnr,datname);
          fstream file(datname, ios::in|ios::binary);
          if(file.is_open())
                file.write((const char*)&amp;toread,sizeof(toread));
          if(file.bad())//Wenn letzter Zugriff schief ging
                throw &quot;Fehler beim lesen der Datei&quot;;//Msg_Box und ab zu catch(..)
          return(toread);//Wenn alles ok
        }
 catch(...)
        {
          //Was soll nun hier stehen?? Das Programm soll nicht abstürzen oder sich selbst beenden
        }
}
</code></pre>
<p>Ich versteh deine Antwort nicht. Formuliers mal anders, bitte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1126785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126785</guid><dc:creator><![CDATA[Croatiancow]]></dc:creator><pubDate>Tue, 29 Aug 2006 11:44:42 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 12:35:52 GMT]]></title><description><![CDATA[<p>Wozu verwendest du hier überhaupt einen try/catch-Block? Lass den in deiner Funktion weg und machen einen um den Aufruf dieser Funktion.<br />
Als Alternative könntest du hier auf Exceptions ganz verzichten und die Funktion ein bool zurückgeben lassen ob sie erfolgreich war. Deine Rechnungs-variable übergibst du als referenz.<br />
[edit]<br />
Bist du sicher, dass du hier etwas schreiben und nicht doch etwa lesen willst? [edit]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1126815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126815</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Tue, 29 Aug 2006 12:35:52 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 12:51:43 GMT]]></title><description><![CDATA[<p>Ja ich will lesen, ich will Feierabend...</p>
<p>Boah sorry Jungs. Schon wieder mein Fehler. Ich will lesen. Keine Ahnung wieso ich den Falschen Body genommen hab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1126824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126824</guid><dc:creator><![CDATA[Croatiancow]]></dc:creator><pubDate>Tue, 29 Aug 2006 12:51:43 GMT</pubDate></item><item><title><![CDATA[Reply to Execption &#x2F; Rückgabewert on Tue, 29 Aug 2006 13:15:22 GMT]]></title><description><![CDATA[<p>Also mal ein Beispiel, wie ich das machen würde.</p>
<pre><code class="language-cpp">bool open_bill(Rechnung&amp; toread, unsigned int nr)
{
     char datname[15]; // Vielleicht besser ein string?
     rechnrtodatname(nr,datname); //Was macht das?
     fstream file(datname, ios::in|ios::binary);
     if(file.is_open())
           file.write((const char*)&amp;toread,sizeof(toread));
     return !file.bad();//Wenn letzter Zugriff schief ging
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1126847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1126847</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Tue, 29 Aug 2006 13:15:22 GMT</pubDate></item></channel></rss>