Message11074

Author stefan.richthofer
Recipients jason_s, stefan.richthofer, zyasoft
Date 2017-02-05.12:45:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486298759.82.0.962262116547.issue2547@psf.upfronthosting.co.za>
In-reply-to
Content
Jason,

I wrote a test-case on my own for this and it appears like Jython already features the behavior you request (maybe this changed since 2.7.0).

Write WrapJavaExceptionTest.java like this:

import org.python.core.PyModule;
import org.python.core.imp;

public class WrapJavaExceptionTest {

	public interface JavaExceptionTester {
		public void raiseTest();
		public void raiseTest2();
	}

	public static String testWrapJavaException() {
		PyModule module = (PyModule) imp.importName("WrapJavaExceptionTest_module", true);
		JavaExceptionTester jt = module.newJ(JavaExceptionTester.class);
		try {
			jt.raiseTest();
			return "no exception";
		} catch (Exception exc) {
			System.out.println("Cause: "+exc.getCause());
			System.out.println("Class: "+exc.getClass());
			return exc.toString();
		}
	}

	public static String testWrapJavaException2() {
		PyModule module = (PyModule) imp.importName("WrapJavaExceptionTest_module", true);
		JavaExceptionTester jt = module.newJ(JavaExceptionTester.class);
		try {
			jt.raiseTest2();
			return "no exception2";
		} catch (Exception exc) {
			System.out.println("Cause: "+exc.getCause());
			System.out.println("Class: "+exc.getClass());
			return exc.toString();
		}
	}
}


Then write WrapJavaExceptionTest_module.py like this:

import WrapJavaExceptionTest
from java.lang import System, RuntimeException

class JavaExceptionTester:
    def raiseTest(self):
        raise RuntimeException("Exceptional message")

    def raiseTest2(self):
        System.getProperty(None)

if __name__ == '__main__':
    print WrapJavaExceptionTest.testWrapJavaException()
    print WrapJavaExceptionTest.testWrapJavaException2()


Run it on current trunk version. You will see that Java catches the exception directly as java.lang.RuntimeException or java.lang.NullPointerException.
Is this scenario still somehow different from what you aim to achieve? In that case, can you modify it to demonstrate the issue?

> I suppose there's some sort of minimal test case, if I can get to it I will but that depends on the workload at my job.

I suppose you'll have to, because it appears I cannot reproduce it ;)
History
Date User Action Args
2017-02-05 12:45:59stefan.richthofersetmessageid: <1486298759.82.0.962262116547.issue2547@psf.upfronthosting.co.za>
2017-02-05 12:45:59stefan.richthofersetrecipients: + stefan.richthofer, zyasoft, jason_s
2017-02-05 12:45:59stefan.richthoferlinkissue2547 messages
2017-02-05 12:45:58stefan.richthofercreate