<?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]]></title><description><![CDATA[<p>Hi Peoples!</p>
<p>Ich hab mir mal ne kleine String Klasse geschrieben (noch nicht ganz fertig) und bin dabei auf das Problem gestoßen, wie man Exceptions erstellt. Zum Beispiel hier:</p>
<pre><code>void CString::Delete(unsigned int index, unsigned int count)
{
   unsigned int len = Length();
   if( (index &gt;= len) || (index + count &gt; len) )
      return;

   LPTSTR substr = m_String + index + count;
   LPTSTR new_pos_substr = m_String + index;
   lstrcpy(new_pos_substr, substr);
}
</code></pre>
<p>Hier stört mich das return; in Zeile 5. Wenn jetzt wirklich was schiefläuft, kriegt man das ja evtl. gar nicht mit. Was mache ich da jetzt am besten?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/151749/exceptions</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 11:42:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/151749.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Jun 2006 09:50:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 09:50:08 GMT]]></title><description><![CDATA[<p>Hi Peoples!</p>
<p>Ich hab mir mal ne kleine String Klasse geschrieben (noch nicht ganz fertig) und bin dabei auf das Problem gestoßen, wie man Exceptions erstellt. Zum Beispiel hier:</p>
<pre><code>void CString::Delete(unsigned int index, unsigned int count)
{
   unsigned int len = Length();
   if( (index &gt;= len) || (index + count &gt; len) )
      return;

   LPTSTR substr = m_String + index + count;
   LPTSTR new_pos_substr = m_String + index;
   lstrcpy(new_pos_substr, substr);
}
</code></pre>
<p>Hier stört mich das return; in Zeile 5. Wenn jetzt wirklich was schiefläuft, kriegt man das ja evtl. gar nicht mit. Was mache ich da jetzt am besten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088182</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Thu, 29 Jun 2006 09:50:08 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 10:03:45 GMT]]></title><description><![CDATA[<p><a href="http://www.cpp-tutor.de/cpp/le17/le17_02.htm" rel="nofollow">http://www.cpp-tutor.de/cpp/le17/le17_02.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088192</guid><dc:creator><![CDATA[People1]]></dc:creator><pubDate>Thu, 29 Jun 2006 10:03:45 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:31:26 GMT]]></title><description><![CDATA[<p>Danke, aber das hat mir jetzt leider gar nicht so viel gebracht. Ich weiß nämlich noch gar nicht, wie ih überhaupt Exceptions verwende. Ist in meinem Fall (s.o. im Code) überhaupt eine nötig? Und wenn ja, wie macht man das? try...catch oder throw? Ich habe echt keine Ahnung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088290</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:31:26 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:34:05 GMT]]></title><description><![CDATA[<p><a href="http://www.cpp-tutor.de/cpp/le16/le16_02.htm" rel="nofollow">http://www.cpp-tutor.de/cpp/le16/le16_02.htm</a> <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>
<p>nimm doch std::string als vorlage und guck wie es da gemacht wird. dort wird soweit ich weiß keine exception geworfen.</p>
<p>wo ist überhaupt der zusammenhang mit winapi?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088291</guid><dc:creator><![CDATA[People1]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:34:05 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:35:05 GMT]]></title><description><![CDATA[<p>WebFritzi schrieb:</p>
<blockquote>
<p>Hier stört mich das return; in Zeile 5. Wenn jetzt wirklich was schiefläuft, kriegt man das ja evtl. gar nicht mit. Was mache ich da jetzt am besten?</p>
</blockquote>
<pre><code class="language-cpp">throw &quot;Hier ging was schief&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1088293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088293</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:35:05 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:39:53 GMT]]></title><description><![CDATA[<p>People1 schrieb:</p>
<blockquote>
<p>wo ist überhaupt der zusammenhang mit winapi?</p>
</blockquote>
<p>Hmm, eigentlich nur meine Klasse, in der ich LPTSTR und all die WinApi-Funktionen kapseln will. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088295</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:39:53 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:38:17 GMT]]></title><description><![CDATA[<p>Also, das hier wäre OK, ja?</p>
<pre><code>void CString::Delete(unsigned int index, unsigned int count) 
{ 
   unsigned int len = Length(); 
   if( (index &gt;= len) || (index + count &gt; len) ) 
      throw(&quot;CString::Delete : one of the integer parameters is too big&quot;); 

   LPTSTR substr = m_String + index + count; 
   LPTSTR new_pos_substr = m_String + index; 
   lstrcpy(new_pos_substr, substr); 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1088297</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088297</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:38:17 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:47:19 GMT]]></title><description><![CDATA[<p>du kannst auch gleich std::basic_string&lt;TCHAR&gt; benutzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088303</guid><dc:creator><![CDATA[anmerkung]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:47:19 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 11:48:28 GMT]]></title><description><![CDATA[<p>Es ist schöner, wenn man eine &quot;Klasse&quot; wirft...</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;tchar.h&gt;

class CMyExp
{
public:
  CMyExp(LPCTSTR szText)
  {
    m_szText = _tcsdup(szText);
  }
  CMyExp(const CMyExp &amp;v)
  {
    m_szText = _tcsdup(v.m_szText);
  }
  ~CMyExp()
  {
    if (m_szText != NULL)
      free(m_szText);
  }
  LPCTSTR toString()
  {
    return m_szText;
  }
private:
  LPTSTR m_szText;

};

int _tmain()
{
  try
  { 
    throw CMyExp(_T(&quot;Hello World!&quot;));
  }
  catch(CMyExp exp)
  {
    _tprintf(exp.toString());
  }
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1088305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088305</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 29 Jun 2006 11:48:28 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions on Thu, 29 Jun 2006 21:44:42 GMT]]></title><description><![CDATA[<p>WebFritzi schrieb:</p>
<blockquote>
<p>Ich weiß nämlich noch gar nicht, wie ih überhaupt Exceptions verwende. Ist in meinem Fall (s.o. im Code) überhaupt eine nötig?</p>
</blockquote>
<p>Ich habe es in meiner String Klasse so gemacht, dass solche Sachen einfach nur geloggt werden. Wenn etwas gelöscht werden soll, was es gar nicht gibt, dann ist das nicht unbedingt ein Grund, weshalb eine Anwendung gleich mit Exceptions um sich werfen soll, imo. Immerhin passiert da ja nix Schlimmes. Dieser logische Fehler des Client muss sicherlich irgendwann beseitigt werden, aber bis dahin kann das Programm auf jeden Fall weiterlaufen. Ich habe für das Logging extra Funktionen/Klassen geschrieben, die die Arbeit übernehmen. Das sieht dann angewendet ungefähr wie folgt aus:</p>
<pre><code class="language-cpp">VERIFY(offset_within_range(index, len));
</code></pre>
<p>Hier würde halt nur geloggt werden, danach aber die Ausführung fortgesetzt werden.<br />
In deinem Fall wäre zB Folgendes notwendig</p>
<pre><code class="language-cpp">VERIFY_RETURN(offset_within_range(index, len));
</code></pre>
<p>Willst du, dass die Anwendung richtig hart bestraft wird, kann man auch Folgendes machen</p>
<pre><code class="language-cpp">VERIFY_ERROR(offset_within_range(index, len));
</code></pre>
<p>Hier fliegt dann halt eine Exception oder die Anwendung wird hart beendet.</p>
<p>Wie auch immer, alles was intern passiert, bleibt transparent. Der Anwender muss sich darum also nicht kümmern. So kann man später die Fehlerbehandlung auch ändern, ohne dass man grossen Aufwand betreiben muss. Von der Benutzung her sind das also alles spezifische Asserts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088741</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Thu, 29 Jun 2006 21:44:42 GMT</pubDate></item></channel></rss>