<?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[c++ exceptions implementierung]]></title><description><![CDATA[<p>hallo,</p>
<p>weiß jemand, wie c++ exceptions implementiert sind?</p>
<p>in windows bzw. mit dem microsoft c++ compiler schaut es ja ungefähr so aus, wenn ich mich recht erinnere:</p>
<p>user mode programm (also &quot;unsere&quot; applikation) macht throw-&gt;soft irq-&gt;betriebssystem interrupt handler fängt interrupt-&gt;aufrufen des exception handlers des usermode programms-&gt;dort dann durchgehen aller handler jeder funktion bis passender handler gefunden wurde.</p>
<p>weiß jemand ob das der regelfall ist, oder ob das auch ganz anders implementiert sein kann?<br />
hat jemand vielleicht eine ahnung, wie es sich unter windows ce verhält bzw. wie man das rausfinden kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/317525/c-exceptions-implementierung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Jul 2026 22:04:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/317525.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Jun 2013 18:00:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to c++ exceptions implementierung on Tue, 11 Jun 2013 18:00:12 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>weiß jemand, wie c++ exceptions implementiert sind?</p>
<p>in windows bzw. mit dem microsoft c++ compiler schaut es ja ungefähr so aus, wenn ich mich recht erinnere:</p>
<p>user mode programm (also &quot;unsere&quot; applikation) macht throw-&gt;soft irq-&gt;betriebssystem interrupt handler fängt interrupt-&gt;aufrufen des exception handlers des usermode programms-&gt;dort dann durchgehen aller handler jeder funktion bis passender handler gefunden wurde.</p>
<p>weiß jemand ob das der regelfall ist, oder ob das auch ganz anders implementiert sein kann?<br />
hat jemand vielleicht eine ahnung, wie es sich unter windows ce verhält bzw. wie man das rausfinden kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330333</guid><dc:creator><![CDATA[fdfdsdfsfdsfsfsf]]></dc:creator><pubDate>Tue, 11 Jun 2013 18:00:12 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Tue, 11 Jun 2013 18:25:23 GMT]]></title><description><![CDATA[<p>fdfdsdfsfdsfsfsf  schrieb:</p>
<blockquote>
<p>weiß jemand, wie c++ exceptions implementiert sind?</p>
</blockquote>
<p>Das ist eine Frage, die Du auch recht leicht hättest ergoogeln können. Erste zwei Treffer von Stackoverflow:</p>
<p><a href="http://stackoverflow.com/questions/490773/how-is-the-c-exception-handling-runtime-implemented" rel="nofollow">http://stackoverflow.com/questions/490773/how-is-the-c-exception-handling-runtime-implemented</a><br />
<a href="http://stackoverflow.com/questions/1995734/how-are-exceptions-implemented-under-the-hood" rel="nofollow">http://stackoverflow.com/questions/1995734/how-are-exceptions-implemented-under-the-hood</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330338</guid><dc:creator><![CDATA[NeunFuenfundneunzig]]></dc:creator><pubDate>Tue, 11 Jun 2013 18:25:23 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 07:31:13 GMT]]></title><description><![CDATA[<p>Exceptions in C++ mittels throw unterscheidet sich von Exceptions/Traps in Betriebssystemen. Ein Aufruf von throw in C++ sollte kein Betriebssystemaufruf ausloesen. Es ist ganz normaler Programmcode wie if oder while ohne syscall.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330443</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 12 Jun 2013 07:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 07:39:05 GMT]]></title><description><![CDATA[<p>wenn Du es etwas einfacher fuer den Einstieg haben willst: Lies Dir mal durch, wie <code>setmp()</code> und <code>longjmp()</code> in C funktionieren. Dann hast Du das Prinzip verstanden.</p>
<p>In C++ kommen noch die Behandlung der Destruktoren fuer das werfende Objekt und die auf dem Stackframe liegenden Objekte dazu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330450</guid><dc:creator><![CDATA[longjmp]]></dc:creator><pubDate>Wed, 12 Jun 2013 07:39:05 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 07:42:35 GMT]]></title><description><![CDATA[<p><a href="http://magazin.c-plusplus.net/artikel/Modernes%20Exception-Handling%20Teil%202%20-%20Hinter%20den%20Kulissen" rel="nofollow">http://magazin.c-plusplus.net/artikel/Modernes Exception-Handling Teil 2 - Hinter den Kulissen</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330453</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 12 Jun 2013 07:42:35 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 08:13:34 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Exceptions in C++ mittels throw unterscheidet sich von Exceptions/Traps in Betriebssystemen. Ein Aufruf von throw in C++ sollte kein Betriebssystemaufruf ausloesen. Es ist ganz normaler Programmcode wie if oder while ohne syscall.</p>
</blockquote>
<p>MSVC verwendet SEH (ein Windows Feature) um C++ Exceptions zu implementieren.<br />
Macht auch mächtig Sinn.<br />
So kann man Exceptions &quot;durch&quot; alles durchwerfen was SEH unterstützt, und das ist auf Windows ziemlich viel.<br />
U.a. das OS selbst, d.h. C++ Exceptions aus einer Callback-Funktion durch die OS Funktion durch und im C++ Programm wieder gefangen = kein Problem.</p>
<p>Genau so C++ Exception aus einer Callback-Funktion durch eine DLL in irgendeiner Sprache (die halt SEH unterstützt) durch und wieder zurück nach C++.</p>
<p>Ist ne feine Sache.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330466</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 12 Jun 2013 08:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 08:26:43 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Es ist ganz normaler Programmcode wie if oder while ohne syscall.</p>
</blockquote>
<p>Das Exception Handling der Itanium C++ ABI kannst du nicht mit normalem Programmcode nachprogrammieren.</p>
<p>Wenn da eine Exception auftritt wird der Instruction Pointer ausgelesen und in einer vom Ausführungscode unabhängigen Tabelle gesucht. Da steht dann der Handlercode. Es ist nicht nur unendlich mühsam, diesen Zero-Cost-Ablauf nachzuprogrammieren, sondern mit Standardmitteln schlicht unmöglich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330471</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330471</guid><dc:creator><![CDATA[fbaetjased]]></dc:creator><pubDate>Wed, 12 Jun 2013 08:26:43 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 08:45:14 GMT]]></title><description><![CDATA[<p>fbaetjased schrieb:</p>
<blockquote>
<p>Es ist nicht nur unendlich mühsam, diesen Zero-Cost-Ablauf nachzuprogrammieren, sondern mit Standardmitteln schlicht unmöglich.</p>
</blockquote>
<p>Unmöglich ist ein hartes Wort. Was daran könntest du denn nicht mit Standardmitteln nachprogrammieren?<br />
Instructionpointer auslesen = magic value im Code beim Werfen der Exception<br />
In einer vom Ausführungscode unabhängigen Tabelle suchen = Globaler Index der magic values<br />
Handlercode anspringen und zum Catch springen = normale Funktionsaufrufe, bei Bedarf longjmp</p>
<blockquote>
<p>Es ist nicht nur unendlich mühsam</p>
</blockquote>
<p>Das ist es wohl. Aber das kann ein Computerprogramm (Compiler) für uns erledigen.</p>
<blockquote>
<p>Zero-Cost-Ablauf</p>
</blockquote>
<p>Wären immer noch 0 Kosten, da die Verwaltungsdaten und Handlercode zur Compilezeit erzeugt wurden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330475</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330475</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 12 Jun 2013 08:45:14 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 08:57:44 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Unmöglich ist ein hartes Wort. Was daran könntest du denn nicht mit Standardmitteln nachprogrammieren?<br />
Instructionpointer auslesen = magic value im Code beim Werfen der Exception</p>
</blockquote>
<p>Über den Instructionpointer kommt Itanium auch an den Callstack (sehr unexakt formuliert).</p>
<p>Wie programmierst du das hier nach?</p>
<pre><code class="language-cpp">&lsqb;&lsqb;noinline&rsqb;&rsqb; void f(int i) {
  if (i == 0) throw 0;
}

void g(int i) {
  lock_guard a; // lock1();
  f(i);
  lock_guard b; // lock2();
  f(i-1);
  // unlock2();
  // unlock1();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2330483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330483</guid><dc:creator><![CDATA[fbaetjased]]></dc:creator><pubDate>Wed, 12 Jun 2013 08:57:44 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 09:19:06 GMT]]></title><description><![CDATA[<p>Was soll der ganze Mist. Das ist das C++ Forum ...</p>
<blockquote>
<p>Itanium C++ ABI</p>
</blockquote>
<p>Und fuer welche Prozessoren/Systeme gibt es denn noch eine C++ ABI und wie unterscheiden sie sich? Ist das im C++ Standard festgelegt. Wenn es spezifisch fuer Winows sein soll, ab ins Windowsforum ...</p>
<p>Auch wird die Ausgangssituation vernachlaessigt:</p>
<blockquote>
<p>user mode programm (also &quot;unsere&quot; applikation) macht throw-&gt;soft irq ...</p>
</blockquote>
<blockquote>
<p>wie es sich unter windows ce verhält bzw. wie man das rausfinden kann</p>
</blockquote>
<p>Ja, man kann die Dokumentation speziell fuer Windows CE lesen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330487</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 12 Jun 2013 09:19:06 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Wed, 12 Jun 2013 10:42:44 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Und fuer welche Prozessoren/Systeme gibt es denn noch eine C++ ABI und wie unterscheiden sie sich?</p>
</blockquote>
<p>Das Itanium-C++-ABI ist nicht unbedingt Itanium-spezifisch. Von einigen IA64-spezifischen Parts abgesehen wird es auch von anderen Compilern implementiert oder zumindest als Leitlinie genommen. Und zwar von jedem mir bekannten C++-Compiler, von MSVC- und Windows-Krams abgesehen</p>
<p><a href="http://mentorembedded.github.io/cxx-abi/abi.html" rel="nofollow">http://mentorembedded.github.io/cxx-abi/abi.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330506</guid><dc:creator><![CDATA[affenbernd]]></dc:creator><pubDate>Wed, 12 Jun 2013 10:42:44 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Thu, 13 Jun 2013 00:25:59 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a><br />
Wie willst du ohne Compiler-Support die Tables erstellen die du brauchst um ohne das Pflegen von dynamischen &quot;wo bin ich&quot; Strukturen zur Runtime, einfach nur aus dem IP + Callstack zu ermitteln welcher Handler zuständig ist und wie das Unwinding ablaufen muss?</p>
<p>In Assembler kann man das nachprogrammieren, ja (wenn auch EXTRAM mühsam). In C++ nicht, nichtmal mit Inline-Assembler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330694</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 13 Jun 2013 00:25:59 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Thu, 13 Jun 2013 07:01:31 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a><br />
Wie willst du ohne Compiler-Support die Tables erstellen die du brauchst um ohne das Pflegen von dynamischen &quot;wo bin ich&quot; Strukturen zur Runtime,</p>
</blockquote>
<p>Ja, ich hatte da an einen Trick gedacht, der aber nicht funktioniert hat. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> Ich fürcht, es gehen nur die nicht-ganz-zero-cost Exceptions, wie man sie teilweise aus anderen Implementierungen kennt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330701</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 13 Jun 2013 07:01:31 GMT</pubDate></item><item><title><![CDATA[Reply to c++ exceptions implementierung on Thu, 13 Jun 2013 07:49:17 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Ich fürcht, es gehen nur die nicht-ganz-zero-cost Exceptions, wie man sie teilweise aus anderen Implementierungen kennt.</p>
</blockquote>
<p>Das &quot;unmöglich&quot; war dadurch motiviert, dass die Fallbackimplementierung des GCCs das typische setjmp/longjmp ist. Wenns was besseres gäbe, hätten die das wahrscheinlich implementiert.</p>
<p>Ignoriert man die Grösse des Binaries sowie Startupzeit, geht es fast:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;setjmp.h&gt;

void _throw_(int n);

template &lt;int N,
          int UniquePrime = 2&gt;
void f(int i) { 
  if (i ==  0) _throw_(UniquePrime*N);
  if (i == 10) _throw_(UniquePrime*UniquePrime*N);
}

void lock() { std::cout &lt;&lt; &quot;lock()\n&quot;; }
void unlock() { std::cout &lt;&lt; &quot;unlock()\n&quot;; }

void g_unwind1() { unlock(); std::cout &lt;&lt; &quot;leave g()\n&quot;; }
void g_unwind2() { unlock(); }

template &lt;int N,
          int UniquePrime = 3&gt;
void g(int i) { 
  std::cout &lt;&lt; &quot;enter g(&quot;&lt;&lt;i&lt;&lt;&quot;)\n&quot;;
  lock();
  f&lt;N*UniquePrime&gt;(i); 
  lock();
  f&lt;N*UniquePrime*UniquePrime&gt;(i-1);
  g_unwind2();
  g_unwind1();
}

static jmp_buf buf;

int main()
{
  switch (setjmp(buf)) { // catch hat einmaligen Overhead, Weil jedes
                         // Programm (mit Codeduplikation) so transformiert
                         // werden kann, dass das catch im main steht.
  case 1: goto i1;
  case 2: goto i2;
  case 3: goto i3;
  case 4: goto i4;
  case 5: goto i5;
  }
  g&lt; 5&gt;( 2); // try { g(); } catch(...) {}
 i1:
  g&lt; 7&gt;( 1); // try { g(); } catch(...) {}
 i2:
  g&lt;11&gt;( 0); // try { g(); } catch(...) {}
 i3:
  g&lt;13&gt;(11); // try { g(); } catch(...) {}
 i4:
  g&lt;17&gt;(10); // try { g(); } catch(...) {}
 i5:;
}

void _throw_(int n)
{
  std::cout &lt;&lt; n &lt;&lt; '\n';
  switch (n) {
  case 2*3*3*7:    g_unwind2(); g_unwind1(); longjmp(buf, 2);
  case 2*3*11:     g_unwind1(); longjmp(buf, 3);
  case 2*2*3*3*13: g_unwind2(); g_unwind1(); longjmp(buf, 4);
  case 2*2*3*17:   g_unwind1(); longjmp(buf, 5);
  default: std::cerr &lt;&lt; &quot;Table not complete: &quot; &lt;&lt; n &lt;&lt; '\n';
  }
}
</code></pre>
<pre><code>enter g(2)
lock()
lock()
unlock()
unlock()
leave g()
enter g(1)
lock()
lock()
126
unlock()
unlock()
leave g()
enter g(0)
lock()
66
unlock()
leave g()
enter g(11)
lock()
lock()
468
unlock()
unlock()
leave g()
enter g(10)
lock()
204
unlock()
leave g()
</code></pre>
<p>Vollständig geht es nur, wenn Parameter+Stackvariablen in einem globalen Array abgelegt werden. In Anbetracht der oben ignorierten Nachteile würde ich aber immer noch als Zero-Cost bezeichnen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2330716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2330716</guid><dc:creator><![CDATA[fbaetjased]]></dc:creator><pubDate>Thu, 13 Jun 2013 07:49:17 GMT</pubDate></item></channel></rss>