+#endif
+}
+
+
+/* exceptions_print_current_exception ******************************************
+
+ Prints the current pending exception, the detail message and the
+ cause, if available, with CACAO internal functions to stdout.
+
+*******************************************************************************/
+
+void exceptions_print_current_exception(void)
+{
+ java_objectheader *xptr;
+
+ xptr = *exceptionptr;
+
+ exceptions_print_exception(xptr);
+}
+
+
+/* exceptions_print_stacktrace *************************************************
+
+ Prints a pending exception with Throwable.printStackTrace(). If
+ there happens an exception during printStackTrace(), we print the
+ thrown exception and the original one.
+
+ NOTE: This function calls Java code.
+
+*******************************************************************************/
+
+void exceptions_print_stacktrace(void)
+{
+ java_objectheader *oxptr;
+ java_objectheader *xptr;
+ classinfo *c;
+ methodinfo *m;
+
+ /* get original exception */
+
+ oxptr = *exceptionptr;
+
+ if (oxptr == NULL)
+ vm_abort("exceptions_print_stacktrace: no exception thrown");
+
+ /* clear exception, because we are calling jit code again */
+
+ *exceptionptr = NULL;
+
+ c = oxptr->vftbl->class;
+
+ /* find the printStackTrace() method */
+
+ m = class_resolveclassmethod(c,
+ utf_printStackTrace,
+ utf_void__void,
+ class_java_lang_Object,
+ false);
+
+ if (m == NULL)
+ vm_abort("exceptions_print_stacktrace: printStackTrace()V not found");
+
+ /* print compatibility message */
+
+ fprintf(stderr, "Exception in thread \"main\" ");
+
+ /* print the stacktrace */
+
+ (void) vm_call_method(m, oxptr);
+
+ /* This normally means, we are EXTREMLY out of memory or
+ have a serious problem while printStackTrace. But may
+ be another exception, so print it. */
+
+ xptr = *exceptionptr;
+
+ if (xptr != NULL) {
+ fprintf(stderr, "Exception while printStackTrace(): ");
+
+ /* now print original exception */
+
+ exceptions_print_exception(xptr);
+ stacktrace_print_trace(xptr);
+
+ /* now print original exception */
+
+ fprintf(stderr, "Original exception was: ");
+ exceptions_print_exception(oxptr);
+ stacktrace_print_trace(oxptr);
+ }
+
+ fflush(stderr);