<?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[&amp;quot;Sauberes&amp;quot; return]]></title><description><![CDATA[<p>Hi Leute,<br />
Ich schreibe momentan ziemlich viele Funktionen, die zurückgeben können bzw. müssen, ob alles geklappt hat, oder nicht. Nur frage ich mich, nach dem Lesen von ziemlich viel Code anderer Leute, was denn die &quot;sauberste&quot; Möglichkeit dafür ist. Nehme man mal als Bsp. eine Texturen-Klasse, die mit SOIL arbeitet und eine Textur laden soll. Was wäre am saubersten...<br />
1.</p>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID != 0)
    {
    return true;
    }
  else
    {
    return false;
    }
  }
(...)
unsigned int ID;
</code></pre>
<ol start="2">
<li></li>
</ol>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID == 0)
    {
    return false;
    }
  else
    {
    return true;
    }
  }
(...)
unsigned int ID;
</code></pre>
<ol start="3">
<li></li>
</ol>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID != 0)
    {
    return true;
    }
  return false;
  }
(...)
unsigned int ID;
</code></pre>
<ol start="4">
<li></li>
</ol>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID == 0)
    {
    return false;
    }
  return true;
  }
(...)
unsigned int ID;
</code></pre>
<p>Danke schon mal im Vo<strong>r</strong>aus(Sone, falls du das liest: <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
<p>MfG<br />
DragonRaider</p>
<p>PS.: Sorry, falls das ins C Forum gehört</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/318086/quot-sauberes-quot-return</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 14:24:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318086.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 30 Jun 2013 15:47:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 15:48:48 GMT]]></title><description><![CDATA[<p>Hi Leute,<br />
Ich schreibe momentan ziemlich viele Funktionen, die zurückgeben können bzw. müssen, ob alles geklappt hat, oder nicht. Nur frage ich mich, nach dem Lesen von ziemlich viel Code anderer Leute, was denn die &quot;sauberste&quot; Möglichkeit dafür ist. Nehme man mal als Bsp. eine Texturen-Klasse, die mit SOIL arbeitet und eine Textur laden soll. Was wäre am saubersten...<br />
1.</p>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID != 0)
    {
    return true;
    }
  else
    {
    return false;
    }
  }
(...)
unsigned int ID;
</code></pre>
<ol start="2">
<li></li>
</ol>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID == 0)
    {
    return false;
    }
  else
    {
    return true;
    }
  }
(...)
unsigned int ID;
</code></pre>
<ol start="3">
<li></li>
</ol>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID != 0)
    {
    return true;
    }
  return false;
  }
(...)
unsigned int ID;
</code></pre>
<ol start="4">
<li></li>
</ol>
<pre><code>bool load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID == 0)
    {
    return false;
    }
  return true;
  }
(...)
unsigned int ID;
</code></pre>
<p>Danke schon mal im Vo<strong>r</strong>aus(Sone, falls du das liest: <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
<p>MfG<br />
DragonRaider</p>
<p>PS.: Sorry, falls das ins C Forum gehört</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335488</guid><dc:creator><![CDATA[DragonRaider]]></dc:creator><pubDate>Sun, 30 Jun 2013 15:48:48 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 15:54:54 GMT]]></title><description><![CDATA[<p>one word: exceptions</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335491</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335491</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Sun, 30 Jun 2013 15:54:54 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:07:44 GMT]]></title><description><![CDATA[<p>Hi dot,<br />
Ist OK. Nur das throw muss ich auch irgendwo hin setzen...<br />
Naja ich schätze mal die Form der Wahl wäre dann:</p>
<pre><code>void load(params)
  {
  ID = SOIL_load_OGL_texture(params);
  if(ID == 0)
    {
    throw &quot;Unable to load texture!&quot;;
    }
  }
(...)
unsigned int ID;
</code></pre>
<p>Oder habe ich dich da was falsch verstanden(habe zwar von throw gehört, es aber, bis jetzt, noch nie genutzt)?</p>
<p>MfG<br />
DragonRaider</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335497</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335497</guid><dc:creator><![CDATA[DragonRaider]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:07:44 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:10:30 GMT]]></title><description><![CDATA[<p>Ja, so geht es zwar, in der Regel schmeißt man aber eine Ausnahmeklassenobjekt.<br />
Die Standardbibliothek bietet hier eine ganze Hierachie an, die alle von std::exception abgeleitet sind.<br />
Dann kann man nämlich einfach</p>
<pre><code>try
{

}
catch (std::exception &amp;ex)
{

}
</code></pre>
<p>um alle Ausnahmen zu fangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335499</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:10:30 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:14:17 GMT]]></title><description><![CDATA[<p>Der Vergleich (==) liefert bereits einen Wahrheitswert. Ein</p>
<pre><code>return ID != 0;
</code></pre>
<p>wäre demnach übersichtlicher gewesen.</p>
<p>Nichts desto trotz sind hier exceptions angebracht. Definiere jedoch eine eigene Ausnahmeklasse (z. B. von std::exception erben) und werfe nicht einfach einen string.</p>
<p>Ave</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335500</guid><dc:creator><![CDATA[Stechus Kaktus]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:14:17 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:22:13 GMT]]></title><description><![CDATA[<p>Hi Nathan,<br />
Danke, für die Hilfe/den Tipp. Ich hab jetzt mal <a href="http://www.google.de" rel="nofollow">www.google.de</a> befragt, da wird folgendes vorgeschlagen:</p>
<pre><code>struct myException : std::exception
{
const char* what() const noexcept
  {
  return &quot;myException(description)&quot;;
  }
};
</code></pre>
<p>Entschuldigung, falls die Frage dumm ist, aber gibt es da auch noch ne &quot;kürzere&quot; Methode? Soweit ich den Code hier verstehe nein, aber...<br />
Danke schon mal bis hier hin <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> .</p>
<p>MfG<br />
DragonRaider</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335503</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335503</guid><dc:creator><![CDATA[DragonRaider]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:22:13 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:34:24 GMT]]></title><description><![CDATA[<p>Ja.<br />
Es gibt die Klasse &quot;runtime_error&quot;, die für deine Fälle ausreicht.<br />
Im Konstruktor übergibst du einfach die Fehlermessage und kannst sie dann abfragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335504</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:34:24 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:47:40 GMT]]></title><description><![CDATA[<p>Nun, Exceptions vs Return-Values. Das haengt von Vorlieben, Objektinvarianten und Programmarchitektur. Ich persoenlich wuerde im vorliegenden Fall keine Exception werfen. Die Exception kann das Objekt in enem ungueltigen Zustand zuruecklassen. Ausserdem wuerden ueberall try-catches auftauschen. Ich wuerde die Texturklasse so gestallten, dass sie mit fehlerhaftem Laden umgehen kann. Das fehlerhafte Laden sollte in der Entwicklung trotzdem in einer Logdatei protokolliert werden.</p>
<p>Eine Moeglichkeit, ist z.B. dass eine leere Textur ein gueltiger Zustand ist und alle Operationen mit Texturen damit umgehen muessen. Das fuehrt dann zu Code wie if(tex.valid()) { ... } else ( ... } und ist auch sehr unschoen.</p>
<p>Meine bevorzugte Moeglichkeit, eine Dummytextur zu nutzen. D.h. bei Fehlschlag wird eine Dummytextur erzeugt. Das Dach des Hauses ist dann eben nicht braun, sondern ist weiss mit roter Schrift &quot;Fix me&quot;. Nachfolgende Operationen brauchen sich dann keine Gedanken machen, ob die Textur gueltig ist. Sie ist es in jedem Fall. Wird die Dummytextur nicht algorithmisch generiert sondern ebenfalls irgendwann am Anfang des Programms geladen, dann wuerde ich eine Exception werfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335509</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:47:40 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 16:51:13 GMT]]></title><description><![CDATA[<p>Meine Texturklasse hat einen Default-Ctor, will man sie aber laden und das schlägt fehl gibts ne Exception. Und das ganze hat sogar noch eine starke Garantie.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335510</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 30 Jun 2013 16:51:13 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 17:13:33 GMT]]></title><description><![CDATA[<blockquote>
<p>starke Garantie</p>
</blockquote>
<p>Das bedeutet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335523</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Sun, 30 Jun 2013 17:13:33 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 17:36:18 GMT]]></title><description><![CDATA[<p>Die Textur an sich ist genau so wie vorher auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335532</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 30 Jun 2013 17:36:18 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 17:52:43 GMT]]></title><description><![CDATA[<p>Hi,<br />
Ich finds echt &quot;schön&quot;, dass sich hier so eine kleine Disskusion los getreten hat <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> . Ich denke, ich werde das mit der &quot;Fix Me&quot; Textur übernehmen und im Releasemode(ohne Konsole) dann auch eine &quot;errors.txt&quot; haben, in der Fehler, verursacht durch fehlende Texturen etc., genau mitgeloggt werden.<br />
Nun zur eigentlichen Frage:<br />
Wenn ich's mit ner boolschen Funktion löse, wäre denn dann 1., 2., 3. oder 4. am saubersten?<br />
MfG<br />
DragonRaider</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335536</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335536</guid><dc:creator><![CDATA[DragonRaider]]></dc:creator><pubDate>Sun, 30 Jun 2013 17:52:43 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Sauberes&amp;quot; return on Sun, 30 Jun 2013 17:57:47 GMT]]></title><description><![CDATA[<p>Stechus Kaktus' Variante?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335539</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Sun, 30 Jun 2013 17:57:47 GMT</pubDate></item></channel></rss>