<?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 werden nicht gefangen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe in etwa folgenden C++ Code</p>
<pre><code class="language-cpp">try{
  Klasse1 klasse;
  try{
    klasse.funktion()
  }
  catch(std::exception e){
    // gib error aus
  }
}
catch(std::exception e){
  // gib error aus
}
</code></pre>
<p>Wenn ich das innere catch weg lasse, fängt der äußere catch Block meine Exception nicht, obwohl diese Typgleich sind. Der innere jedoch fängt diese korrekt. Einziger Unterschied: in der äußeren steckt halt noch der Konstruktor mit drin, aber der wirft selbst keine Exception (schon getestet).</p>
<p>Woran könnte's liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/258988/exceptions-werden-nicht-gefangen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 02:21:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/258988.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Jan 2010 21:21:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 21:21:34 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe in etwa folgenden C++ Code</p>
<pre><code class="language-cpp">try{
  Klasse1 klasse;
  try{
    klasse.funktion()
  }
  catch(std::exception e){
    // gib error aus
  }
}
catch(std::exception e){
  // gib error aus
}
</code></pre>
<p>Wenn ich das innere catch weg lasse, fängt der äußere catch Block meine Exception nicht, obwohl diese Typgleich sind. Der innere jedoch fängt diese korrekt. Einziger Unterschied: in der äußeren steckt halt noch der Konstruktor mit drin, aber der wirft selbst keine Exception (schon getestet).</p>
<p>Woran könnte's liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1840456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840456</guid><dc:creator><![CDATA[smartpanda]]></dc:creator><pubDate>Sun, 17 Jan 2010 21:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 21:29:58 GMT]]></title><description><![CDATA[<p>Bitte sehr, gern geschehen. Jetzt kann man es entziffern. <em>&quot;Wo sind wir denn gewesen ...&quot;</em></p>
<pre><code class="language-cpp">try
{
	Klasse1 klasse;

	try
	{
		klasse.funktion()
	}
	catch(std::exception e)
	{
		// gib error aus
	}
}
catch(std::exception e)
{
	// gib error aus
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1840460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840460</guid><dc:creator><![CDATA[Entfrickl0r]]></dc:creator><pubDate>Sun, 17 Jan 2010 21:29:58 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 21:32:29 GMT]]></title><description><![CDATA[<p>Entziffern konnte man es auch vorher.</p>
<p>Allerdings zwei andere Dinge:<br />
1. Ein ausführbares Minimalbeispiel wäre hier sehr hilfreich. Kann unter Umständen sogar dir helfen, den Fehler zu finden.<br />
2. Man fängt eigentlich Referenzen und nicht Kopien.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1840461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840461</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sun, 17 Jan 2010 21:32:29 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 21:43:41 GMT]]></title><description><![CDATA[<p>Danke für deine Antwort, das mit den Referenzen wusst ich noch nicht. Werd ich beachten.</p>
<p>Das mit dem ausführbaren Minibeispiel ist nicht so einfach, da die Klasse relativ komplex ist:</p>
<pre><code class="language-cpp">#include &lt;exception&gt;
#include &lt;iostream&gt;

class testMe{
 public:
  testMe();
  void funktion(){
    throw std::exception;
  }
};

int main(int argc, char** argv){
  try{
    testMe tester;
    try{
      tester.funktion();
    }
    catch(std::exception &amp;e){
      std::cerr &lt;&lt; &quot;Exception gefangen&quot; &lt;&lt; std::endl;
    }
  }
  catch(std::exception &amp;f){
    std::cout &lt;&lt; &quot;Exception gefangen&quot; &lt;&lt; std::endl;
  }
}
</code></pre>
<p>Das wäre es denke ich minimal, um zu verstehen was intern abgeht. Zu Testzwecken habe ich meiner wirklichen Funktion wirklich ein derartiges throw an die erste Zeile gestellt, es hängt also nicht vom Inhalt der Funktion ab.</p>
<p>Wenn ich das gleiche (throw an die erste Zeile) allerdings innerhalb des Konstruktors selbst mache, funktioniert es (der äußere Block fängt die Exception). Hilft dir das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1840468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840468</guid><dc:creator><![CDATA[smartpanda]]></dc:creator><pubDate>Sun, 17 Jan 2010 21:43:41 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 22:16:12 GMT]]></title><description><![CDATA[<p>Wenn man die Syntaxfehler in deinem Beispiel korrigiert, dann funktioniert das einwandfrei. Gib uns bitte wirklich mal 1:1 ein Minimalbeispiel von dem, was bei dir nicht funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1840488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840488</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 17 Jan 2010 22:16:12 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 22:54:16 GMT]]></title><description><![CDATA[<p>main.cpp</p>
<pre><code class="language-cpp">extern &quot;C&quot;{
	#include &lt;libavformat/avformat.h&gt;
}

#include &quot;types.h&quot;

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;stdexcept&gt;

#include &quot;openCLProgram.h&quot;

using namespace GRAVID;

int main(int argc, char** argv){
	try{
		OpenCLProgram tester;
		try{
		tester.loadProgram(&quot;src/opencl/kernels/colorFilters.cl&quot;,&quot;grayFilter&quot;);
		}
		catch(std::logic_error e){
			std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
		}
	}
	catch(std::logic_error e){
		std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
		exit(-1);
	}
</code></pre>
<p>OpenCLProgram.h</p>
<pre><code class="language-cpp">#ifndef OPENCLPROGRAM_H_
#define OPENCLPROGRAM_H_

#include &lt;CL/cl.h&gt;
#include &lt;stdexcept&gt;
#include &lt;string&gt;

#include &quot;types.h&quot;

namespace GRAVID{
	class OpenCLProgram{
		private:
			// for opencl return codes
			cl_int errorCode;

			// the number of OpenCL capable platforms
			cl_uint nb_platforms;
			// the available platform ids
			cl_platform_id *pPlatformIDs;

			// the number of devices for the first platform
			cl_uint nb_devices;
			// the ids of the devices available for the first platform
			cl_device_id *pDeviceIDs;

			// the OpenCL context
			cl_context clCtx;
			// the current cl-program
			cl_program clProgram;
			// the loaded kernel within the loaded source
			cl_kernel clKernel;
			// the command queue for that kernel
			cl_command_queue cmdQ;

			void errorHappened(const char* error);

			std::string readKernel(const char* filename);

		public:
			OpenCLProgram();
			~OpenCLProgram();

			void loadProgram(const char* filename, const char* kernelName);
}

#endif /* OPENCLPROGRAM_H_ */
</code></pre>
<p>OpenCLProgram.cpp</p>
<pre><code class="language-cpp">#include &quot;openCLProgram.h&quot;
#include &quot;types.h&quot;

#include &lt;CL/cl.h&gt;
#include &lt;stdexcept&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;

using namespace GRAVID;

OpenCLProgram::OpenCLProgram(){
	// retrieve platform ids
	this-&gt;pPlatformIDs = NULL;
	clGetPlatformIDs(NULL,NULL,&amp;(this-&gt;nb_platforms));
	// stop, if there is no OpenCL platform
	if(0 == this-&gt;nb_platforms)
		this-&gt;errorHappened(&quot;no OpenCL capable platforms available&quot;);
	this-&gt;pPlatformIDs = new cl_platform_id[this-&gt;nb_platforms]; // some memory is allocated that has to be freed in the destructor
	this-&gt;errorCode = clGetPlatformIDs(this-&gt;nb_platforms,this-&gt;pPlatformIDs,NULL);
	if(CL_SUCCESS != this-&gt;errorCode)
		this-&gt;errorHappened(&quot;couldn't get the platform ids&quot;);

	// obtain the list of GPUs for the first platform
	this-&gt;pDeviceIDs = NULL;
	clGetDeviceIDs(this-&gt;pPlatformIDs[0],CL_DEVICE_TYPE_GPU, NULL, NULL, &amp;this-&gt;nb_devices);
	// stop, if there is no device available
	if(0 == this-&gt;nb_devices)
			this-&gt;errorHappened(&quot;no device available for the first platform&quot;);
	this-&gt;pDeviceIDs = new cl_device_id[this-&gt;nb_devices];
	this-&gt;errorCode = clGetDeviceIDs(this-&gt;pPlatformIDs[0],CL_DEVICE_TYPE_GPU, this-&gt;nb_devices, this-&gt;pDeviceIDs, NULL);
	if(CL_SUCCESS != this-&gt;errorCode)
			this-&gt;errorHappened(&quot;couldn't get the device ids&quot;);

	// create a context for the devices to use
	cl_context_properties clContProperties[3];
	clContProperties[0] = CL_CONTEXT_PLATFORM;
	clContProperties[1] = (cl_context_properties)this-&gt;pPlatformIDs[0];
	clContProperties[2] = 0;
	this-&gt;clCtx = clCreateContext(clContProperties,this-&gt;nb_devices,this-&gt;pDeviceIDs,NULL,NULL,&amp;this-&gt;errorCode);
	if(CL_SUCCESS != this-&gt;errorCode)
		this-&gt;errorHappened(&quot;couldn't create context&quot;);
}

void OpenCLProgram::errorHappened(const char* error){
	std::string errorMsg = error;
	throw std::logic_error(errorMsg);
}

OpenCLProgram::~OpenCLProgram(){

	clReleaseCommandQueue(this-&gt;cmdQ);

	clReleaseKernel(this-&gt;clKernel);

	clReleaseProgram(this-&gt;clProgram);

	clReleaseContext(this-&gt;clCtx);

	if(NULL != this-&gt;pDeviceIDs)
			delete(this-&gt;pDeviceIDs);

	if(NULL != this-&gt;pPlatformIDs)
		delete(this-&gt;pPlatformIDs);
}

std::string OpenCLProgram::readKernel(const char* filename){
	std::ifstream inFile;
	char buffer[256];
	std::string resultString;

	inFile.open(filename,std::ifstream::in);
	if(inFile.fail())
		this-&gt;errorHappened(&quot;kernel source-file not found&quot;);

	while(inFile.good()){
		inFile.getline(buffer,256);
		resultString.append(buffer);
	}

	inFile.close();
	return resultString;
}

void OpenCLProgram::loadProgram(const char* filename, const char* kernelName){

	// retrieve the kernel source
	std::string kernelString = this-&gt;readKernel(filename);
	const char* kernel_cstr = kernelString.c_str();
	size_t kernelLength = (size_t)kernelString.length();
	this-&gt;clProgram = clCreateProgramWithSource(this-&gt;clCtx, 1, &amp;kernel_cstr, &amp;kernelLength,&amp;this-&gt;errorCode);
	if(CL_SUCCESS != this-&gt;errorCode)
		this-&gt;errorHappened(&quot;couldn't create program from source&quot;);

	// build the program
	// TODO check if there maybe a built version already exists
	this-&gt;errorCode = clBuildProgram(this-&gt;clProgram,NULL,NULL,NULL,NULL,NULL);
	// get Build Information
	size_t actualSize;
	clGetProgramBuildInfo(this-&gt;clProgram,this-&gt;pDeviceIDs[0],CL_PROGRAM_BUILD_LOG,NULL,NULL,&amp;actualSize);
	char errorMessage[actualSize];
	clGetProgramBuildInfo(this-&gt;clProgram,this-&gt;pDeviceIDs[0],CL_PROGRAM_BUILD_LOG,actualSize,(void*)errorMessage,NULL);
	if(CL_SUCCESS != this-&gt;errorCode){
		std::string totalError = &quot;Building process failed with the following error log:\n&quot;;
		totalError.append(errorMessage);
		this-&gt;errorHappened(totalError.c_str());
	}

	// extract the kernel within the program
	this-&gt;clKernel = clCreateKernel(this-&gt;clProgram,kernelName,&amp;this-&gt;errorCode);
	if(CL_SUCCESS != this-&gt;errorCode)
		this-&gt;errorHappened(&quot;couldn't extract the specified kernel from the loaded source&quot;);

	// creating the commandQueue for the kernel
	this-&gt;cmdQ = clCreateCommandQueue(this-&gt;clCtx, this-&gt;pDeviceIDs[0], NULL, &amp;this-&gt;errorCode);
	if(CL_SUCCESS != this-&gt;errorCode)
		this-&gt;errorHappened(&quot;couldn't create command queue&quot;);
}
</code></pre>
<p>Sry, but I couldn't post less to make it work (or in this case not work).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1840510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840510</guid><dc:creator><![CDATA[smartpanda]]></dc:creator><pubDate>Sun, 17 Jan 2010 22:54:16 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Sun, 17 Jan 2010 22:55:17 GMT]]></title><description><![CDATA[<p>Achja und sry dafür dass mir manchmal die Srachorientierung fehlt <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1840511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840511</guid><dc:creator><![CDATA[smartpanda]]></dc:creator><pubDate>Sun, 17 Jan 2010 22:55:17 GMT</pubDate></item><item><title><![CDATA[Reply to Exceptions werden nicht gefangen on Mon, 18 Jan 2010 00:13:47 GMT]]></title><description><![CDATA[<p>keine angst - das mit der sprachorientierung wird niemanden stören - weil du offenbar nicht fähig bist ein _compilierbares minimalbeispiel_ zu posten...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1840537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1840537</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 18 Jan 2010 00:13:47 GMT</pubDate></item></channel></rss>