|
37 | 37 | import org.jruby.*; |
38 | 38 | import org.jruby.exceptions.*; |
39 | 39 | import org.jruby.runtime.*; |
| 40 | +import org.jruby.util.Asserts; |
40 | 41 |
|
41 | 42 | /** |
42 | 43 | * |
@@ -83,27 +84,23 @@ public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { |
83 | 84 | Object receiver = !singleton ? ((RubyJavaObject)recv).getValue() : null; |
84 | 85 |
|
85 | 86 | return JavaUtil.convertJavaToRuby(ruby, method.invoke(receiver, newArgs)); |
86 | | - } catch (Exception e) { |
87 | | - throw convertException(ruby, e); |
| 87 | + } catch (InvocationTargetException itExcptn) { |
| 88 | + convertException(ruby, (Exception)itExcptn.getTargetException()); |
| 89 | + |
| 90 | + return ruby.getNil(); |
| 91 | + } catch (Exception excptn) { |
| 92 | + Asserts.assertNotReached(); |
| 93 | + return null; |
88 | 94 | } |
89 | 95 | } |
90 | 96 |
|
91 | | - private static RuntimeException convertException(Ruby ruby, Exception e) { |
| 97 | + private static void convertException(Ruby ruby, Exception e) { |
92 | 98 | if (e instanceof RaiseException) { |
93 | | - return (RaiseException) e; |
| 99 | + throw (RaiseException) e; |
94 | 100 | } else if (e instanceof IOException) { |
95 | | - return IOError.fromException(ruby, (IOException) e); |
| 101 | + throw IOError.fromException(ruby, (IOException) e); |
96 | 102 | } else { |
97 | | - StringWriter stackTrace = new StringWriter(); |
98 | | - e.printStackTrace(new PrintWriter(stackTrace)); |
99 | | - |
100 | | - StringBuffer sb = new StringBuffer(); |
101 | | - sb.append("Native Exception: '"); |
102 | | - sb.append(e.getClass()).append("\'; Message: "); |
103 | | - sb.append(e.getMessage()); |
104 | | - sb.append("; StackTrace: "); |
105 | | - sb.append(stackTrace.getBuffer().toString()); |
106 | | - throw new RaiseException(ruby, "RuntimeError", sb.toString()); |
| 103 | + ruby.getJavaSupport().handleNativeException(e); |
107 | 104 | } |
108 | 105 | } |
109 | 106 |
|
|
0 commit comments