SDK sample for exceptions with C++

Create a single thread for each patch to be added to the repository. Please try to stay on topic.
Post Reply
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

SDK sample for exceptions with C++

Post by Heimdall »

SDK sample for exceptions with C++

It seems that some people don't know how to use it.

Code: Select all

Index: pspsdk/src/samples/Makefile.am
===================================================================
--- pspsdk/src/samples/Makefile.am	(working copy)
+++ pspsdk/src/samples/Makefile.am	(working copy)
@@ -81,7 +81,8 @@
 	utility/osk \
 	me/basic \
-	wlan
+	wlan \
+	exceptions
 
 all:
 
Index: pspsdk/src/samples/exceptions/main.cpp
===================================================================
--- pspsdk/src/samples/exceptions/main.cpp	(revision 0)
+++ pspsdk/src/samples/exceptions/main.cpp	(revision 0)
@@ -0,0 +1,50 @@
+#include <pspkernel.h>
+#include <pspdebug.h>
+#include <pspctrl.h>
+
+/* Define printf, just to make typing easier */
+#define printf  pspDebugScreenPrintf
+
+/* Define the module info section */
+PSP_MODULE_INFO&#40;"cppException", 0, 1, 1&#41;;
+
+/* Define the main thread's attribute value &#40;optional&#41; */
+PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;
+
+#include <exception>
+using namespace std;
+
+class myexception&#58; public exception
+&#123;
+	virtual const char* what&#40;&#41; const throw&#40;&#41;
+	&#123;
+		return "My exception happened";
+	&#125;
+&#125; myex;
+
+int main &#40;void&#41;
+&#123;
+	pspDebugScreenInit&#40;&#41;;
+	SceCtrlData pad;
+	
+	try
+	&#123;
+		throw myex;
+	&#125;
+	catch &#40;exception& e&#41;
+	&#123;
+		printf&#40;"%s\n", e.what&#40;&#41;&#41;;
+	&#125;
+	
+	printf&#40;"\nPress X to quit.\n"&#41;;
+
+	for &#40;;;&#41;
+	&#123;
+		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
+		if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;
+			break;
+	&#125;
+	sceKernelExitGame&#40;&#41;;
+
+	return 0;
+&#125;
Index&#58; pspsdk/src/samples/exceptions/Makefile.sample
===================================================================
--- pspsdk/src/samples/exceptions/Makefile.sample	&#40;revision 0&#41;
+++ pspsdk/src/samples/exceptions/Makefile.sample	&#40;revision 0&#41;
@@ -0,0 +1,18 @@
+TARGET = CppException
+OBJS = main.o
+LIBS = -lstdc++
+
+INCDIR =
+CFLAGS = -G0 -Wall -O2
+CXXFLAGS = $&#40;CFLAGS&#41; -fno-rtti -fexceptions
+ASFLAGS = $&#40;CFLAGS&#41;
+
+LIBDIR =
+LDFLAGS =
+
+EXTRA_TARGETS = EBOOT.PBP
+PSP_EBOOT_TITLE = C++ Exception Sample
+
+PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
+include $&#40;PSPSDK&#41;/lib/build.mak
+
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

I can't get it to apply, can you upload it somewhere (nopaste.org or similar)?
Post Reply