javacommons/utils/src/debugutils.cpp
branchRCL_3
changeset 77 7cee158cb8cd
parent 19 04becd199f91
child 83 26b2b12093af
--- a/javacommons/utils/src/debugutils.cpp	Tue Sep 14 21:06:50 2010 +0300
+++ b/javacommons/utils/src/debugutils.cpp	Wed Sep 15 12:05:25 2010 +0300
@@ -39,3 +39,28 @@
     ThreadDump::closeDumper();
 }
 
+/**
+ * A utility for getting the stack trace for further processing.
+ * @param th The throwable from where the stack trace should be get.
+ * @param printStream Where to print the stack trace.
+ */
+JNIEXPORT void JNICALL
+Java_com_nokia_mj_impl_utils_DebugUtils__1getStackTrace
+(JNIEnv* jniEnv, jclass, jthrowable th, jobject printStream)
+{
+    /*
+     * call Throwable.printStackTrace(java.io.PrintStream)
+     * this method is not part of CLDC spec, but it's supported by VM vendor.
+     */
+    jclass classThrowable = jniEnv->GetObjectClass(th);
+    if (classThrowable)
+    {
+        jmethodID methodId = jniEnv->GetMethodID(classThrowable,
+                             "printStackTrace",
+                             "(Ljava/io/PrintStream;)V");
+        if (methodId)
+        {
+            jniEnv->CallVoidMethod(th, methodId, printStream);
+        }
+    }
+}