<?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[[Frage zu folg. Programm] ExecptionHandling und Ausgabe]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin dabei mich wieder in c++ einzuarbeiten und hänge im Moment an folgendem Beispiel fest.</p>
<pre><code class="language-cpp">/* 
 * Was wird von dem nachfolgenden Programm auf die Standardausgabe ausgegeben?
 */

#include &lt;iostream&gt;
using namespace std;

class A 
{
public:
	A(int i);
	A(const A&amp; a);
	~A();
	int info() const;
private:
	int ia;
};

A::A(int i) : ia(i) { cout &lt;&lt; &quot;A:Konstruktor &quot; &lt;&lt; ia &lt;&lt; endl; }
A::A(const A&amp; a) : ia(a.ia) { cout &lt;&lt; &quot;A:Kopierkonstruktor &quot; &lt;&lt; ia &lt;&lt; endl; }
A::~A() { cout &lt;&lt; &quot;A:Destruktor &quot; &lt;&lt; ia &lt;&lt; endl; }
int A::info() const { return ia; }

void f(A a) throw (const char*, int)
{
	cout &lt;&lt; &quot;Beginn f(&quot; &lt;&lt; a.info() &lt;&lt; &quot;)&quot; &lt;&lt; endl;
	if (a.info() &gt; 5) { 
		throw &quot;a.info() &gt; 5&quot;;
	} else if (a.info() &gt; 2 ) {
		throw a.info();
	}
	cout &lt;&lt; &quot;Ende f(&quot; &lt;&lt; a.info() &lt;&lt; &quot;)&quot; &lt;&lt; endl;
}

int g(int i)
{
	cout &lt;&lt; &quot;Beginn g(&quot; &lt;&lt; i &lt;&lt; &quot;)&quot; &lt;&lt; endl;
	switch(i - (i / 2) * 2) 
	{
		case 0: { i += 3; } break; 
		case 1: { i *= 2; } break; 
	}

#define VERSION1
#ifdef VERSION1
	A a1(i);
	try { 
		f(a1); 
	}
#else
	try { 
		A a1(i);
		f(a1); 
	}
#endif
	catch (int i) { cout &lt;&lt; &quot;g: int-Ausnahme &quot; &lt;&lt; i &lt;&lt; endl; }
	catch (const char* s) { cout &lt;&lt; &quot;g: char*-Ausnahme &quot; &lt;&lt; s &lt;&lt; endl; throw; }
	cout &lt;&lt; &quot;Ende g(&quot; &lt;&lt; i &lt;&lt; &quot;)&quot; &lt;&lt; endl;
	return i;
}

int main() 
{
/*  1 */	cout &lt;&lt; &quot;Beginn main()&quot; &lt;&lt; endl;
/*  2 */	int i = 1;
/*  3 */	try { 
/*  4 */	    	while (i &lt; 10) 
                    { i = g(i); }
/*  5 */	    } 
/*  6 */	catch (int i) { cout &lt;&lt; &quot;main: int-Ausnahme &quot; &lt;&lt; i &lt;&lt; endl; }
/*  7 */	catch (const char* s) { cout &lt;&lt; &quot;main: char*-Ausnahme &quot; &lt;&lt; s &lt;&lt; endl; }
/*  8 */	cout &lt;&lt; &quot;Ende main()&quot; &lt;&lt; endl;
cin.get();
/*  9 */	return 0;
}
</code></pre>
<p>Kann mir bitte jemand erklären, weshalb bei int i = 1 der Konstruktor als erstes in der Ausgabe erscheint und kein &quot;Begin main()&quot; im Ablauf erscheint?<br />
Ich blicke da im Moment nur halb durch, wie welche Funktion die Werte übergibt.</p>
<p>Hoffe auf Erklärungen, um den genauen Ablauf zu verstehen!</p>
<p>dankeschön!!</p>
<p>ciao<br />
Daniel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/154198/frage-zu-folg-programm-execptionhandling-und-ausgabe</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 19:14:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/154198.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Jul 2006 11:15:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Frage zu folg. Programm] ExecptionHandling und Ausgabe on Tue, 25 Jul 2006 11:15:35 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin dabei mich wieder in c++ einzuarbeiten und hänge im Moment an folgendem Beispiel fest.</p>
<pre><code class="language-cpp">/* 
 * Was wird von dem nachfolgenden Programm auf die Standardausgabe ausgegeben?
 */

#include &lt;iostream&gt;
using namespace std;

class A 
{
public:
	A(int i);
	A(const A&amp; a);
	~A();
	int info() const;
private:
	int ia;
};

A::A(int i) : ia(i) { cout &lt;&lt; &quot;A:Konstruktor &quot; &lt;&lt; ia &lt;&lt; endl; }
A::A(const A&amp; a) : ia(a.ia) { cout &lt;&lt; &quot;A:Kopierkonstruktor &quot; &lt;&lt; ia &lt;&lt; endl; }
A::~A() { cout &lt;&lt; &quot;A:Destruktor &quot; &lt;&lt; ia &lt;&lt; endl; }
int A::info() const { return ia; }

void f(A a) throw (const char*, int)
{
	cout &lt;&lt; &quot;Beginn f(&quot; &lt;&lt; a.info() &lt;&lt; &quot;)&quot; &lt;&lt; endl;
	if (a.info() &gt; 5) { 
		throw &quot;a.info() &gt; 5&quot;;
	} else if (a.info() &gt; 2 ) {
		throw a.info();
	}
	cout &lt;&lt; &quot;Ende f(&quot; &lt;&lt; a.info() &lt;&lt; &quot;)&quot; &lt;&lt; endl;
}

int g(int i)
{
	cout &lt;&lt; &quot;Beginn g(&quot; &lt;&lt; i &lt;&lt; &quot;)&quot; &lt;&lt; endl;
	switch(i - (i / 2) * 2) 
	{
		case 0: { i += 3; } break; 
		case 1: { i *= 2; } break; 
	}

#define VERSION1
#ifdef VERSION1
	A a1(i);
	try { 
		f(a1); 
	}
#else
	try { 
		A a1(i);
		f(a1); 
	}
#endif
	catch (int i) { cout &lt;&lt; &quot;g: int-Ausnahme &quot; &lt;&lt; i &lt;&lt; endl; }
	catch (const char* s) { cout &lt;&lt; &quot;g: char*-Ausnahme &quot; &lt;&lt; s &lt;&lt; endl; throw; }
	cout &lt;&lt; &quot;Ende g(&quot; &lt;&lt; i &lt;&lt; &quot;)&quot; &lt;&lt; endl;
	return i;
}

int main() 
{
/*  1 */	cout &lt;&lt; &quot;Beginn main()&quot; &lt;&lt; endl;
/*  2 */	int i = 1;
/*  3 */	try { 
/*  4 */	    	while (i &lt; 10) 
                    { i = g(i); }
/*  5 */	    } 
/*  6 */	catch (int i) { cout &lt;&lt; &quot;main: int-Ausnahme &quot; &lt;&lt; i &lt;&lt; endl; }
/*  7 */	catch (const char* s) { cout &lt;&lt; &quot;main: char*-Ausnahme &quot; &lt;&lt; s &lt;&lt; endl; }
/*  8 */	cout &lt;&lt; &quot;Ende main()&quot; &lt;&lt; endl;
cin.get();
/*  9 */	return 0;
}
</code></pre>
<p>Kann mir bitte jemand erklären, weshalb bei int i = 1 der Konstruktor als erstes in der Ausgabe erscheint und kein &quot;Begin main()&quot; im Ablauf erscheint?<br />
Ich blicke da im Moment nur halb durch, wie welche Funktion die Werte übergibt.</p>
<p>Hoffe auf Erklärungen, um den genauen Ablauf zu verstehen!</p>
<p>dankeschön!!</p>
<p>ciao<br />
Daniel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103726</guid><dc:creator><![CDATA[ichichich]]></dc:creator><pubDate>Tue, 25 Jul 2006 11:15:35 GMT</pubDate></item><item><title><![CDATA[Reply to [Frage zu folg. Programm] ExecptionHandling und Ausgabe on Tue, 25 Jul 2006 11:21:40 GMT]]></title><description><![CDATA[<pre><code>Beginn main()
Beginn g(1)
A:Konstruktor 2
A:Kopierkonstruktor 2
Beginn f(2)
Ende f(2)
A:Destruktor 2
Ende g(2)
A:Destruktor 2
Beginn g(2)
A:Konstruktor 5
A:Kopierkonstruktor 5
Beginn f(5)
A:Destruktor 5
g: int-Ausnahme 5
Ende g(5)
A:Destruktor 5
Beginn g(5)
A:Konstruktor 10
A:Kopierkonstruktor 10
Beginn f(10)
A:Destruktor 10
g: char*-Ausnahme a.info() &gt; 5
A:Destruktor 10
main: char*-Ausnahme a.info() &gt; 5
Ende main()
</code></pre>
<p>Das ist die genaue Ausgabe bei mir. Welchen Compiler benutzt du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103729</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Tue, 25 Jul 2006 11:21:40 GMT</pubDate></item><item><title><![CDATA[Reply to [Frage zu folg. Programm] ExecptionHandling und Ausgabe on Tue, 25 Jul 2006 11:32:24 GMT]]></title><description><![CDATA[<p>hmmm...komisch jetzt kommt das auch bei mir raus, obwohl ich vorher nix geändert hatte. Wird wohl die Hitze sein, sorry <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/1103738</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103738</guid><dc:creator><![CDATA[ichichich]]></dc:creator><pubDate>Tue, 25 Jul 2006 11:32:24 GMT</pubDate></item></channel></rss>