diff --git a/Examples/test-suite/java/java_throws_runme.java b/Examples/test-suite/java/java_throws_runme.java index 63b6497bc..b27eef11d 100644 --- a/Examples/test-suite/java/java_throws_runme.java +++ b/Examples/test-suite/java/java_throws_runme.java @@ -27,20 +27,34 @@ public class java_throws_runme { catch (CloneNotSupportedException e) {} catch (IllegalAccessException e) {} - if (!pass) { - System.err.println("Test 1 failed"); - System.exit(1); - } + if (!pass) + throw new RuntimeException("Test 1 failed"); // Check the exception class in the throw typemap + pass = false; try { java_throws.throw_spec_function(100); } catch (IllegalAccessException e) { pass = true; } - if (!pass) { - System.err.println("Test 2 failed"); - System.exit(1); + if (!pass) + throw new RuntimeException("Test 2 failed"); + + // Check newfree typemap throws attribute + try { + TestClass tc = java_throws.makeTestClass(); } + catch (NoSuchMethodException e) {} + + // Check javaout typemap throws attribute + pass = false; + try { + int myInt = java_throws.ioTest(); + } + catch (java.io.IOException e) { pass = true; } + + if (!pass) + throw new RuntimeException("Test 4 failed"); + } } diff --git a/Examples/test-suite/java_throws.i b/Examples/test-suite/java_throws.i index 7f342410c..15145b183 100644 --- a/Examples/test-suite/java_throws.i +++ b/Examples/test-suite/java_throws.i @@ -39,3 +39,37 @@ short full_of_exceptions(int num) { void throw_spec_function(int value) throw (int) { throw (int)0; } %} + +// Check newfree typemap throws attribute +%newobject makeTestClass; +%typemap(newfree, throws="NoSuchMethodException") TestClass* "/*not written*/" +%inline %{ +class TestClass { + int x; +public: + TestClass(int xx) : x(xx) {} +}; +TestClass* makeTestClass() { return new TestClass(1000); } +%} + + +// javain typemap throws attribute +// Will only compile if the fileFunction has a java.io.IOException throws clause as getCanonicalPath() throws this exception +%typemap(jstype) char* someFileArgument "java.io.File" +%typemap(javain, throws="java.io.IOException") char* someFileArgument "$javainput.getCanonicalPath()" + +%inline %{ +void fileFunction(char* someFileArgument) {} +%} + + +// javout typemap throws attribute +%typemap(javaout, throws="java.io.IOException") int { + int returnValue=$jnicall; + if (returnValue==0) throw new java.io.IOException("some IOException"); + return returnValue; + } + +%inline %{ +int ioTest() { return 0; } +%}