<?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[Exception wird nicht gefangen]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich habe folgendes Problem:<br />
Ich lade in mein Hauptprogramm eine dynamische Library und beziehe ein Objekt &quot;account&quot;, welches in dieser Library erstellt wird.</p>
<p>Anschliessend rufe ich eine Methode dieses Objekts auf und fange mögliche Exceptions.</p>
<pre><code class="language-cpp">try {
    account-&gt;initialize();
} catch (EException&amp; e) {
    throw e; // (1)
} catch (std::runtime_error&amp; e) {
    throw e; // (2)
} catch (...) {
    throw e; // (3)
}
</code></pre>
<p>Wenn ich nun in der &quot;initialize&quot;-Methode eine Runtime-Exception werfe</p>
<pre><code class="language-cpp">throw std::runtime_error(&quot;test&quot;);
</code></pre>
<p>dann wird diese wie erwartet in (2) weitergeleitet.</p>
<p>Weiter habe ich eine Klasse EException erstellt, welche von std::runtime_error erbt und in einer statischen Library liegt. Diese statische Library wird von der Hauptapplikation, wie auch von der dynamischen Library reingelinkt.</p>
<p>Wenn ich nun in &quot;initialize&quot; eine EException werfe:</p>
<pre><code class="language-cpp">throw EException(&quot;test&quot;);
</code></pre>
<p>dann wird diese Exception in (3) weitergeleitet. Wieso?!?</p>
<p>Kennt jemand dieses Problem und weiss, wie man dies lösen kann?</p>
<p>Besten Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/263282/exception-wird-nicht-gefangen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 20:29:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/263282.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 18 Mar 2010 10:48:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 10:48:09 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich habe folgendes Problem:<br />
Ich lade in mein Hauptprogramm eine dynamische Library und beziehe ein Objekt &quot;account&quot;, welches in dieser Library erstellt wird.</p>
<p>Anschliessend rufe ich eine Methode dieses Objekts auf und fange mögliche Exceptions.</p>
<pre><code class="language-cpp">try {
    account-&gt;initialize();
} catch (EException&amp; e) {
    throw e; // (1)
} catch (std::runtime_error&amp; e) {
    throw e; // (2)
} catch (...) {
    throw e; // (3)
}
</code></pre>
<p>Wenn ich nun in der &quot;initialize&quot;-Methode eine Runtime-Exception werfe</p>
<pre><code class="language-cpp">throw std::runtime_error(&quot;test&quot;);
</code></pre>
<p>dann wird diese wie erwartet in (2) weitergeleitet.</p>
<p>Weiter habe ich eine Klasse EException erstellt, welche von std::runtime_error erbt und in einer statischen Library liegt. Diese statische Library wird von der Hauptapplikation, wie auch von der dynamischen Library reingelinkt.</p>
<p>Wenn ich nun in &quot;initialize&quot; eine EException werfe:</p>
<pre><code class="language-cpp">throw EException(&quot;test&quot;);
</code></pre>
<p>dann wird diese Exception in (3) weitergeleitet. Wieso?!?</p>
<p>Kennt jemand dieses Problem und weiss, wie man dies lösen kann?</p>
<p>Besten Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870764</guid><dc:creator><![CDATA[Spatz]]></dc:creator><pubDate>Thu, 18 Mar 2010 10:48:09 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 12:36:52 GMT]]></title><description><![CDATA[<p>OT: Du solltest <em>(re)throw</em>und nicht <em>throw e</em> verwenden.<br />
<a href="http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.9" rel="nofollow">http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.9</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870818</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870818</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 18 Mar 2010 12:36:52 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 13:34:01 GMT]]></title><description><![CDATA[<p>Du solltest in den catchs immer konstante Referenzen behandeln:</p>
<pre><code class="language-cpp">catch (std::runtime_error const&amp; err)
{
    throw;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1870842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870842</guid><dc:creator><![CDATA[Biolunar]]></dc:creator><pubDate>Thu, 18 Mar 2010 13:34:01 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 13:37:46 GMT]]></title><description><![CDATA[<p>Biolunar schrieb:</p>
<blockquote>
<p>Du solltest in den catchs immer konstante Referenzen behandeln:</p>
<pre><code class="language-cpp">catch (std::runtime_error const&amp; err)
{
    throw;
}
</code></pre>
</blockquote>
<p>Ist nicht zwingend und manchmal nicht sinnvoll (z.B. wenn zusätzliche Information hinzugefügt werden soll).<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870843</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 18 Mar 2010 13:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 13:38:03 GMT]]></title><description><![CDATA[<p>Aber du kompilierst schon alles mit dem selben Compiler/selben Einstellungen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870844</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Thu, 18 Mar 2010 13:38:03 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 13:44:57 GMT]]></title><description><![CDATA[<p>Welcher Compiler? Exceptions über Programm/Library-Grenzen hinweg waren schon immer ein unangenehmes Thema...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870851</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870851</guid><dc:creator><![CDATA[*rant*]]></dc:creator><pubDate>Thu, 18 Mar 2010 13:44:57 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 14:45:48 GMT]]></title><description><![CDATA[<p>/rant/ schrieb:</p>
<blockquote>
<p>Welcher Compiler? Exceptions über Programm/Library-Grenzen hinweg waren schon immer ein unangenehmes Thema...</p>
</blockquote>
<p>Ich verwende gcc 4.4.1 und ja, ich kompiliere alles mit der selben Umgebung und Einstellungen.</p>
<p>Const kann ich nicht machen, da ich in der Tat noch weitere Informationen an die Exception anhänge. Zudem besteht das Problem auch mit Verwendung von const.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870883</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870883</guid><dc:creator><![CDATA[Spatz]]></dc:creator><pubDate>Thu, 18 Mar 2010 14:45:48 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 15:43:25 GMT]]></title><description><![CDATA[<p>Hmm.<br />
Der Standard schreibt nichts vor, also ist das eher ein Verhalten von GCC.</p>
<p>Schau mal hier:<br />
<a href="http://stackoverflow.com/questions/2424836/exceptions-are-not-caught-in-gcc-program" rel="nofollow">http://stackoverflow.com/questions/2424836/exceptions-are-not-caught-in-gcc-program</a></p>
<p>Also mal noch die Option</p>
<pre><code>-shared-libgcc
</code></pre>
<p>anhängen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870926</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 18 Mar 2010 15:43:25 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 15:56:36 GMT]]></title><description><![CDATA[<p>Unter der Annahme, dass du beim Kompilieren der Bibliothek -fvisibility=hidden benutzt (was bei Bibliotheken durchaus üblich ist): Du musst die gesamte Exception-Klasse mit __attribute__(visibility(&quot;default&quot;)) versehen, sonst wird die vtable nicht exportiert, und beim Fangen der Exception schlägt das Nachschlagen der typeinfo fehl.</p>
<p>Das ganze ist hier beschrieben: <a href="http://gcc.gnu.org/wiki/Visibility" rel="nofollow">http://gcc.gnu.org/wiki/Visibility</a> (Unterpunkt &quot;Problems with C++ exceptions&quot;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870939</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Thu, 18 Mar 2010 15:56:36 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 16:31:54 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>Hmm.<br />
Der Standard schreibt nichts vor, also ist das eher ein Verhalten von GCC.</p>
<p>Schau mal hier:<br />
<a href="http://stackoverflow.com/questions/2424836/exceptions-are-not-caught-in-gcc-program" rel="nofollow">http://stackoverflow.com/questions/2424836/exceptions-are-not-caught-in-gcc-program</a></p>
<p>Also mal noch die Option</p>
<pre><code>-shared-libgcc
</code></pre>
<p>anhängen.</p>
</blockquote>
<p>Vielen Dank für diesen Tipp!<br />
Es funktioniert nun schon etwas besser. Wenn ich eine &quot;EException&quot; werfe, dann lande ich immerhin schon in (2).<br />
Aber eben leider immer noch nicht in (1)...</p>
<p>Hab mir das mit der Visibility mal Durchgelesen und in &quot;EException&quot; eingebaut. Dies ändert jedoch nichts (weder am Verhalten, noch in der Ausgabe von &quot;nm -C -D &lt;library&gt;.so&quot; wie ganz unten auf der Seite deines Links angegeben).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870958</guid><dc:creator><![CDATA[Spatz]]></dc:creator><pubDate>Thu, 18 Mar 2010 16:31:54 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Thu, 18 Mar 2010 17:23:03 GMT]]></title><description><![CDATA[<p>Du landest mit der <code>EException</code> im Handler für <code>std::runtime_error</code> ?!</p>
<p>WTF?<br />
Hmm. Ich würde mal sagen, dass du den Fehler am ehesten mit solchen Flags beheben kannst. Der Code und dein Vorgehen ist imo schon korrekt.<br />
Vielleich findest du noch mehr Compilerspezifisches dazu.</p>
<p>Ich bin so drauf gestossen:<br />
<a href="http://www.google.ch/search?q=gcc+exception+not+caught&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;client=firefox-a&amp;rlz=1R1GGGL_de___CH343" rel="nofollow">http://www.google.ch/search?q=gcc+exception+not+caught&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;client=firefox-a&amp;rlz=1R1GGGL_de___CH343</a></p>
<p>Da hat es noch eine Menge anderer Themen mit dem gleichen/ähnlichen Problem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870968</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870968</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 18 Mar 2010 17:23:03 GMT</pubDate></item><item><title><![CDATA[Reply to Exception wird nicht gefangen on Fri, 19 Mar 2010 13:43:32 GMT]]></title><description><![CDATA[<p>Vielen vielen Dank an alle!!</p>
<p>Hab diesen Fehler endlich beheben können.<br />
Als erstes hat das Compilerflag &quot;-shared-libgcc&quot; erste Erfolge verzeichnet.<br />
Nach etwas googeln hab ich auch noch erfahren, dass Exceptions über Librarygrenzen hinaus nur funktioniert, wenn man keine Methoden-Implementationen in den Exception-Header Dateien hat.<br />
Sobald ich diese in die Source-Dateien verschoben habe, hat es funktioniert!</p>
<p>Hab zur Sicherheit auch noch das Visibility-Flag gesetzt.</p>
<p>Nochmals allen vielen Dank. Hab wirklich lange an diesem Fehler gesessen. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1871294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1871294</guid><dc:creator><![CDATA[Spatz]]></dc:creator><pubDate>Fri, 19 Mar 2010 13:43:32 GMT</pubDate></item></channel></rss>