<?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[Exceptions filtern und weiterleiten]]></title><description><![CDATA[<p>Um Exceptions zu filtern möchte ich folgende Konstruktion einsetzen. Ich bin mir aber nicht sicher, ab das vielleicht auf andere Weise eleganter zu realisieren ist.</p>
<p>Der Sinn von Folgendem ist nur, dass keine Exception ungeprüft geworfen wird und NUR exceptions vom Typ &lt;MyException&gt; geworfen werden.</p>
<pre><code class="language-cpp">enum MyExceptionID {
  MY_BAD,
  MY_FATAL,
};

class MyException: public std::exception {
public:
  explicit MyException(MyExceptionID id) :
      std::exception(&quot;MyException&quot;), m_id(id) {
  }

  MyExceptionID ExceptionID() const {
    return m_id;
  }

private:
  MyExceptionID m_id;
};

void Function(const std::string&amp; string) {
  try {
    if (string == &quot;runtime_error&quot;) {
      throw std::runtime_error(&quot;runtime_error&quot;);  // std::runtime_error
    }

    if (string == &quot;MyException&quot;) {
      throw MyException(MY_BAD);                  // MyException
    }

    // Do complex operations that could throw various exceptions
    // ...
    std::string temp(string);
    std::string::size_type pos = temp.rfind(&quot;,&quot;);
    temp.erase(pos);                              // std::out_of_range
    // ...
  } catch (const MyException&amp; e) {
    // Forward the exception
    throw e;
  } catch (const std::exception&amp; e) {
    // Do something with the exception
    // ...
    throw MyException(MY_FATAL);
  }
}

int main() {
  try {
    Function(&quot;missingcomma&quot;);
  } catch (const MyException&amp; e) {
    std::cout &lt;&lt; &quot;My Exception: &quot; &lt;&lt; e.ExceptionID() &lt;&lt; std::endl;
  }

  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/309490/exceptions-filtern-und-weiterleiten</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 06:30:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/309490.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Oct 2012 11:11:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 11:13:45 GMT]]></title><description><![CDATA[<p>Um Exceptions zu filtern möchte ich folgende Konstruktion einsetzen. Ich bin mir aber nicht sicher, ab das vielleicht auf andere Weise eleganter zu realisieren ist.</p>
<p>Der Sinn von Folgendem ist nur, dass keine Exception ungeprüft geworfen wird und NUR exceptions vom Typ &lt;MyException&gt; geworfen werden.</p>
<pre><code class="language-cpp">enum MyExceptionID {
  MY_BAD,
  MY_FATAL,
};

class MyException: public std::exception {
public:
  explicit MyException(MyExceptionID id) :
      std::exception(&quot;MyException&quot;), m_id(id) {
  }

  MyExceptionID ExceptionID() const {
    return m_id;
  }

private:
  MyExceptionID m_id;
};

void Function(const std::string&amp; string) {
  try {
    if (string == &quot;runtime_error&quot;) {
      throw std::runtime_error(&quot;runtime_error&quot;);  // std::runtime_error
    }

    if (string == &quot;MyException&quot;) {
      throw MyException(MY_BAD);                  // MyException
    }

    // Do complex operations that could throw various exceptions
    // ...
    std::string temp(string);
    std::string::size_type pos = temp.rfind(&quot;,&quot;);
    temp.erase(pos);                              // std::out_of_range
    // ...
  } catch (const MyException&amp; e) {
    // Forward the exception
    throw e;
  } catch (const std::exception&amp; e) {
    // Do something with the exception
    // ...
    throw MyException(MY_FATAL);
  }
}

int main() {
  try {
    Function(&quot;missingcomma&quot;);
  } catch (const MyException&amp; e) {
    std::cout &lt;&lt; &quot;My Exception: &quot; &lt;&lt; e.ExceptionID() &lt;&lt; std::endl;
  }

  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2263482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263482</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Wed, 24 Oct 2012 11:13:45 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 11:20:09 GMT]]></title><description><![CDATA[<p>Wsa erscheint dir denn daran unelegant? Du könntest jetzt noch eine Funktion höherer Ordnung schreiben, die das try-catch-Zeug automatisch um deine Funktion herum schreibt.</p>
<p>Aber noch ein paar Kommentare: Eine Exception wirft man durch <code>throw;</code> weiter, ohne Parameter. Alle weiteren Exceptions würde ich mit <code>catch(...)</code> fangen, weil jemand nicht von std::exception geerbt haben könnte. Das const bei den Exceptions ist auch ziemlich überflüssig, weil Exceptions by value geworfen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263489</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263489</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Wed, 24 Oct 2012 11:20:09 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 11:27:12 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Wsa erscheint dir denn daran unelegant? Du könntest jetzt noch eine Funktion höherer Ordnung schreiben, die das try-catch-Zeug automatisch um deine Funktion herum schreibt.</p>
<p>Aber noch ein paar Kommentare: Eine Exception wirft man durch <code>throw;</code> weiter, ohne Parameter. Alle weiteren Exceptions würde ich mit <code>catch(...)</code> fangen, weil jemand nicht von std::exception geerbt haben könnte. Das const bei den Exceptions ist auch ziemlich überflüssig, weil Exceptions by value geworfen werden.</p>
</blockquote>
<p>Danke für den Hinweis mit const!</p>
<p>Das catch(...) wollte ich eigentlich vermeiden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263495</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263495</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Wed, 24 Oct 2012 11:27:12 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 11:39:26 GMT]]></title><description><![CDATA[<p>Tomahawk schrieb:</p>
<blockquote>
<pre><code class="language-cpp">} catch (const MyException&amp; e) {
    // Forward the exception
    throw e;
  }
</code></pre>
</blockquote>
<p>Das ist besser als</p>
<pre><code class="language-cpp">} catch (const MyException&amp;) {
    // Forward the exception
    throw; // &lt;-- ohne Objekt
  }
</code></pre>
<p>geschrieben, sonst kriegst du Slicing-Probleme, wenn jemand von deiner Exceptionklasse erbt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263497</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263497</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Wed, 24 Oct 2012 11:39:26 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 12:12:41 GMT]]></title><description><![CDATA[<p>seldon schrieb:</p>
<blockquote>
<p>Tomahawk schrieb:</p>
<blockquote>
<pre><code class="language-cpp">} catch (const MyException&amp; e) {
    // Forward the exception
    throw e;
  }
</code></pre>
</blockquote>
<p>Das ist besser als</p>
<pre><code class="language-cpp">} catch (const MyException&amp;) {
    // Forward the exception
    throw; // &lt;-- ohne Objekt
  }
</code></pre>
<p>geschrieben, sonst kriegst du Slicing-Probleme, wenn jemand von deiner Exceptionklasse erbt.</p>
</blockquote>
<p>Da musste ich jetzt genau hinschauen. Beim Querlesen habe ich erst mal nur</p>
<p>Code</p>
<p>Das ist besser als</p>
<p>Code</p>
<p>gesehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263505</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 24 Oct 2012 12:12:41 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 13:20:38 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Das const bei den Exceptions ist auch ziemlich überflüssig, weil Exceptions by value geworfen werden.</p>
</blockquote>
<p>Wenn man etwas <code>const</code> machen kann, ist das nie überflüssig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263535</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Wed, 24 Oct 2012 13:20:38 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 14:30:59 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Wenn man etwas <code>const</code> machen kann, ist das nie überflüssig.</p>
</blockquote>
<p>Schreibst du das so?</p>
<pre><code class="language-cpp">const int verdopple(const int i)
{
    return 2 * i;
}
</code></pre>
<p>Und so?</p>
<pre><code class="language-cpp">const int verdopple(const int* const i)
{
    return 2 * (*i);
}
</code></pre>
<p>Edit: double ist kein toller Funktionsname.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263593</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Wed, 24 Oct 2012 14:30:59 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 15:50:38 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>TyRoXx schrieb:</p>
<blockquote>
<p>Wenn man etwas <code>const</code> machen kann, ist das nie überflüssig.</p>
</blockquote>
<p>Schreibst du das so?</p>
<pre><code class="language-cpp">const int verdopple(const int i)
{
    return 2 * i;
}
</code></pre>
<p>Und so?</p>
<pre><code class="language-cpp">const int verdopple(const int* const i)
{
    return 2 * (*i);
}
</code></pre>
</blockquote>
<p>An so einen Schwachsinn habe ich bei der Behauptung natürlich nicht gedacht. Ich würde es falsch nennen, einen Rückgabewert <code>const</code> zu machen, nicht &quot;überflüssig&quot;.<br />
Das bei den Argumenten kann man bei der Definition von mir aus machen. Warum sollte man die anders behandeln als andere lokale Variablen?<br />
Man macht die Parameter aber nicht <code>const</code> , damit die Parameterlisten bei Deklaration und Definition gleich sind (bzw. damit man die nicht jeweils anpassen muss).<br />
Wenn man einfach bei beidem <code>const</code> schreibt, steht in der Deklaration ein Implementationsdetail. Für den Benutzer der Funktion nutzlos und eher störend.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263626</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Wed, 24 Oct 2012 15:50:38 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:05:33 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>...</p>
</blockquote>
<p>Wieso falsch? Überflüssig trifft es viel besser:</p>
<p>1. Wenn du Argumente by-value übergibst, machst du die Parameter nicht <code>const</code> , da es redundant wäre. Du kannst das Original sowieso nicht ändern, da du ja nur eine Kopie zur Verfügung hast.</p>
<p>2. Wenn du einen fundamentalen Typen by-value zurückgibst, machst du den Rückgabetypen nicht <code>const</code> , da es redundant wäre, da der Rückgabewert per Definition ein <code>rvalue</code> ist. Einem <code>rvalue</code> kannst du eh nichts zuweisen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263636</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263636</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:06:22 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Warum sollte man die anders behandeln als andere lokale Variablen?</p>
</blockquote>
<p>Du lieferst im nächsten Satz selbst ein Argument: Was meinst du eigentlich mit &quot;damit man die nicht jeweils anpassen muss&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263637</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263637</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:06:22 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:56:17 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>2. Wenn du einen fundamentalen Typen by-value zurückgibst, machst du den Rückgabetypen nicht <code>const</code> , da es redundant wäre, da der Rückgabewert per Definition ein <code>rvalue</code> ist. Einem <code>rvalue</code> kannst du eh nichts zuweisen.</p>
</blockquote>
<p>Laut C++11 ein prvalue. <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/2263662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263662</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:56:17 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:38:05 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>1. Wenn du Argumente by-value übergibst, machst du die Parameter nicht <code>const</code> , da es redundant wäre. Du kannst das Original sowieso nicht ändern, da du ja nur eine Kopie zur Verfügung hast.</p>
</blockquote>
<p>Wieso? Ich nutze <code>const</code> wo ich kann. Und damit garantiert man dem Aufrufer und sich selbst, dass der Parameter im Verlauf der Funktion immer denselben Wert hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263663</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:38:05 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:45:17 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>1. Wenn du Argumente by-value übergibst, machst du die Parameter nicht <code>const</code> , da es redundant wäre. Du kannst das Original sowieso nicht ändern, da du ja nur eine Kopie zur Verfügung hast.</p>
</blockquote>
<p>Aber die Kopie kann geändert werden.</p>
<p>out schrieb:</p>
<blockquote>
<p>2. Wenn du einen fundamentalen Typen by-value zurückgibst, machst du den Rückgabetypen nicht <code>const</code> , da es redundant wäre, da der Rückgabewert per Definition ein <code>rvalue</code> ist. Einem <code>rvalue</code> kannst du eh nichts zuweisen.</p>
</blockquote>
<p>Man kann ihn aber als LValue binden und dann möchte man kein <code>const</code> . Wegen der Einheitlichkeit und weil es keinen positiven Effekt hat, schreibt man generell nicht <code>const</code> bei Rückgabewerten. Es ist sozusagen falsch.</p>
<p>Michael E. schrieb:</p>
<blockquote>
<p>TyRoXx schrieb:</p>
<blockquote>
<p>Warum sollte man die anders behandeln als andere lokale Variablen?</p>
</blockquote>
<p>Du lieferst im nächsten Satz selbst ein Argument: Was meinst du eigentlich mit &quot;damit man die nicht jeweils anpassen muss&quot;?</p>
</blockquote>
<p>Deklaration: Kein <code>const</code> weil das ein Implementationsdetail ist und nicht zur Signatur gehört.<br />
Definition: <code>const</code> , weil sinnvoll.<br />
Man müsste also ständig darauf achten, <code>const</code> zu ergänzen oder zu entfernen. C++ ist aber schon Tipperei genug. Es ist damit nicht unnötig, sondern unpraktisch.</p>
<p>Mal was zum Anfassen:</p>
<pre><code class="language-cpp">//so soll das für den Benutzer aussehen
int add(int a, int b);

//ist länger ohne Mehrwert
int add(int const a, int const b); 

//const verhindert versehentliches Ändern
int add(int const a, int const b)
{
	some_obscure_call(a); //wird a hier geändert? Ah, kann nicht wegen const.

	for (int i = 0; i &lt; a; ++a); //Tippfehler kompiliert nicht

	return a + b;
}
</code></pre>
<p>Sone schrieb:</p>
<blockquote>
<p>out schrieb:</p>
<blockquote>
<p>1. Wenn du Argumente by-value übergibst, machst du die Parameter nicht <code>const</code> , da es redundant wäre. Du kannst das Original sowieso nicht ändern, da du ja nur eine Kopie zur Verfügung hast.</p>
</blockquote>
<p>Wieso? Ich nutze <code>const</code> wo ich kann. Und damit garantiert man dem Aufrufer und sich selbst, dass der Parameter im Verlauf der Funktion immer denselben Wert hat.</p>
</blockquote>
<p>Dem Aufrufer ist es egal, welche Werte die Kopie annimmt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263666</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:40:19 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Laut C++11 ein prvalue.</p>
</blockquote>
<p>prvalues sind rvalues. Einfach mal die... du weisst schon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263667</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:40:19 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:56:04 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>Laut C++11 ein prvalue.</p>
</blockquote>
<p>prvalues sind rvalues.</p>
</blockquote>
<p>C++11 macht einen Unterschied zwischen prvalue und rvalue. Sonst würde man nicht zwei unterschiedliche Ausdrucksklassen daraus machen.</p>
<p>Dass es hier irrelevant ist, dürfte mehr als offensichtlich sein <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/2263670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263670</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:56:04 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 16:56:53 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Dem Aufrufer ist es egal, welche Werte die Kopie annimmt.</p>
</blockquote>
<p>Naja, ich dachte, wenn er nach Bugs in der Implementierung sucht... <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2263671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263671</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 16:56:53 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:00:10 GMT]]></title><description><![CDATA[<p>Mir gefaellt const in der Signatur deshalb nicht, weil es implementierungsdetails nach aussen traegt.</p>
<p>Bestes Beispiel ist hier wohl strcpy:</p>
<pre><code class="language-cpp">char* strcpy(char* trg, char const* src);
</code></pre>
<p>das muesste ja wenn ich ueberall const schreibe wo ich const schreiben kann so lauten:</p>
<pre><code class="language-cpp">char* const strcpy(char* const trg, char const* const src);
</code></pre>
<p>Das const beim Returntyp ignorieren wir mal, weil das ein anderes Thema ist. Betrachten wir nun aber die Standard Implementierung von strcpy:</p>
<pre><code class="language-cpp">while(*trg++=*src++)
  ;
</code></pre>
<p>geht aber jetzt nicht mehr. Doof sowas. Wir muessen jetzt ploetzlich unnoetig kopieren.</p>
<p>Es gibt einige Gruende warum ich den Parameter aendern will. Und in der Signatur erkennt man nun ob ich das tue. Sowas mag ich nicht.</p>
<p>Prinzipiell ist const ueberall zu schreiben toll, wenn man dann aber inkonsistent werden muss, ists doof. Und ueberall Kopien ziehen will ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263672</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:00:10 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:06:27 GMT]]></title><description><![CDATA[<p>Wieso ist es so ein &quot;Problem&quot;, wenn du verrätst dass du innen den Zeiger veränderst? Klar, du willst Implementierungsdetails geheim halten. Aber das ist doch wirklich etwas übertrieben...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263673</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:06:27 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:08:33 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Wieso? Ich nutze <code>const</code> wo ich kann. Und damit garantiert man dem Aufrufer und sich selbst, dass der Parameter im Verlauf der Funktion immer denselben Wert hat.</p>
</blockquote>
<p>Du hast es nicht verstanden: Wenn du <code>by-value</code> machst, dann weiß der Aufrufer doch schon längst, dass sein Argument auch nach der Funktion noch denselben Wert hat, da das Argument ja kopiert wird, verstehst du?<br />
Wenn du als Entwickler sichergehen willst, dass der Parameter stets denselben Wert hat, machst du den Parameter trotzdem nicht const:</p>
<p>1. Weil es den Aufrufer verwirrt. Er wundert sich, dass bei by-value der Paramter <code>const</code> ist und will wissen, was es damit auf sich hat.</p>
<p>2. Du legst damit Implementierungsdetails frei. Dass ein Parameter in der Funktion nicht verändert werden darf, geht doch den Aufrufer nichts an. Das Offenlegen von Implementierungsdetails wird als schlechtes objektorientiertes Progammieren angesehen.</p>
<p>Willst du also sichergehen, dass der Parameter stets denselben Wert hat, machst du das so:</p>
<pre><code class="language-cpp">void fkt(int i)
{
    const int&amp; ci = i;
    // und erst jetzt beginnt die eigentliche Arbeit der Funktion.
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2263674</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263674</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:08:33 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:09:28 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Wieso ist es so ein &quot;Problem&quot;, wenn du verrätst dass du innen den Zeiger veränderst? Klar, du willst Implementierungsdetails geheim halten. Aber das ist doch wirklich etwas übertrieben...</p>
</blockquote>
<p>Weil es inkonsistent ist.</p>
<p>Warum sind bei Funktion A die Parameter const und bei Funktion B nicht? Wenn du solche Sachen dann vor dir hast, ueberlegst du erstmal. Was macht B anders als A. Was vorallem dann lustig ist und dich auf vollkommen falsche Faehrten fuehrt, wenn du einen Bug suchst <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>Mal von dem Prinzip abgesehen, dass man Never Ever Ever Implementierungsdetails verraet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263675</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:09:28 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:12:04 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>Wieso? Ich nutze <code>const</code> wo ich kann. Und damit garantiert man dem Aufrufer und sich selbst, dass der Parameter im Verlauf der Funktion immer denselben Wert hat.</p>
</blockquote>
<p>Du hast es nicht verstanden: Wenn du <code>by-value</code> machst, dann weiß der Aufrufer doch schon längst, dass sein Argument auch nach der Funktion noch denselben Wert hat, da das Argument ja kopiert wird, verstehst du?</p>
</blockquote>
<p>Das habe ich schon lange kapiert, keine Sorge. Ich weiß, was by-value heißt <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>
<blockquote>
<p>Wenn du als Entwickler sichergehen willst, dass der Parameter stets denselben Wert hat, machst du den Parameter trotzdem nicht const:</p>
<p>1. Weil es den Aufrufer verwirrt. Er wundert sich, dass bei by-value der Paramter <code>const</code> ist und will wissen, was es damit auf sich hat.</p>
<p>2. Du legst damit Implementierungsdetails frei. Dass ein Parameter in der Funktion nicht verändert werden darf, geht doch den Aufrufer nichts an. Das Offenlegen von Implementierungsdetails wird als schlechtes objektorientiertes Progammieren angesehen.</p>
<p>Willst du also sichergehen, dass der Parameter stets denselben Wert hat, machst du das so:</p>
<pre><code class="language-cpp">void fkt(int i)
{
    const int&amp; ci = i;
    // und erst jetzt beginnt die eigentliche Arbeit der Funktion.
}
</code></pre>
</blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Mal von dem Prinzip abgesehen, dass man Never Ever Ever Implementierungsdetails verraet.</p>
</blockquote>
<p>Na bitte, sowas wollte ich hören.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263677</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:12:04 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:11:59 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>C++11 macht einen Unterschied zwischen prvalue und rvalue. Sonst würde man nicht zwei unterschiedliche Ausdrucksklassen daraus machen.</p>
<p>Dass es hier irrelevant ist, dürfte mehr als offensichtlich sein <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>
</blockquote>
<p>Ein rvalue ist entweder ein prvalue oder ein xvalue. Was an meiner Aussage jetzt falsch ist, darfst du mir also erklaeren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263678</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:11:59 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:13:54 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>C++11 macht einen Unterschied zwischen prvalue und rvalue. Sonst würde man nicht zwei unterschiedliche Ausdrucksklassen daraus machen.</p>
<p>Dass es hier irrelevant ist, dürfte mehr als offensichtlich sein <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>
</blockquote>
<p>Ein rvalue ist entweder ein prvalue oder ein xvalue. Was an meiner Aussage jetzt falsch ist, darfst du mir also erklaeren.</p>
</blockquote>
<p>Gar nichts. Die hat keiner in Frage gestellt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263679</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:13:54 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:16:29 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Na bitte, sowas wollte ich hören.</p>
</blockquote>
<p>Jut. <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="😉"
    /> Und noch zum Abschluss: <a href="http://www.devx.com/tips/Tip/26546" rel="nofollow">http://www.devx.com/tips/Tip/26546</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263680</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263680</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:16:29 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:31:40 GMT]]></title><description><![CDATA[<p>Es kommt mir so vor als wüssten einige hier nicht, dass man das schreiben darf:</p>
<pre><code class="language-cpp">void f(int a);

void f(int const a) {}
</code></pre>
<p><a href="http://www.devx.com/tips/Tip/26546" rel="nofollow">http://www.devx.com/tips/Tip/26546</a> schrieb:</p>
<blockquote>
<p>const in pass-by-value is indeed redundant. The function can't make changes to the original variable anyway, because it has a local copy thereof. Now one can argue that even in that case, the use of const documents the fact that the function doesn't change its local copy. However, do we really care about this? If you are the implementer of the function, you probably do but you certainly don't need to document this fact, as it is merely an implementation detail, not a part of the interface. Users of this function certainly don't care; all they need to know is that the original variable can't be altered, and the use of pass-by-value, with or without const, already guarantees that. To conclude, the use of const in pass-by-value is an example of over-specification that exposes an implementation detail. In general, exposing implementation details is bad object-oriented programming practice.</p>
</blockquote>
<p>Der Typ weiß das auch nicht.<br />
Typischer Blödsinn eines &quot;real programmer&quot;, der den Sinn von <code>const</code> nicht verstanden hat. Der verwendet wahrscheinlich <code>delete</code> bei Arrays und vergleicht <code>float</code> mit <code>==</code> . Ist ja schließlich in seinem (kurzen und oberflächlichen) Programmiererdasein noch nie schiefgegangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263685</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:31:40 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions filtern und weiterleiten on Wed, 24 Oct 2012 17:53:37 GMT]]></title><description><![CDATA[<p>Was hast du an dem Text auszusetzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2263688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2263688</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 24 Oct 2012 17:53:37 GMT</pubDate></item></channel></rss>