]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java
(refs #7326) Better handling of exceptions in Java->SCL interface
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / utils / ValueFromMethod.java
index 70160dee2615b4e284e637134b1efcf7e03e84a5..1c8c6431f89b16310fd41232b8fd580294463215 100644 (file)
@@ -27,8 +27,13 @@ public class ValueFromMethod {
                 Object ret = method.invoke(null, p0);
                 return returnsVoid ? Tuple0.INSTANCE : ret;
             } catch (ReflectiveOperationException e) {
-                if (e instanceof InvocationTargetException)
-                    throw new RuntimeException(e.getCause());
+                if (e instanceof InvocationTargetException) {
+                    Throwable cause = e.getCause();
+                    if(cause instanceof RuntimeException)
+                        throw (RuntimeException)cause;
+                    else
+                        throw new RuntimeException(cause);
+                }
                 throw new RuntimeException(e);
             }
         }
@@ -66,6 +71,13 @@ public class ValueFromMethod {
                 Object ret = method.invoke(null, p0, p1);
                 return returnsVoid ? Tuple0.INSTANCE : ret;
             } catch (ReflectiveOperationException e) {
+                if (e instanceof InvocationTargetException) {
+                    Throwable cause = e.getCause();
+                    if(cause instanceof RuntimeException)
+                        throw (RuntimeException)cause;
+                    else
+                        throw new RuntimeException(cause);
+                }
                 throw new RuntimeException(e);
             }
         }
@@ -103,6 +115,13 @@ public class ValueFromMethod {
                 Object ret = method.invoke(null, p0, p1, p2);
                 return returnsVoid ? Tuple0.INSTANCE : ret;
             } catch (ReflectiveOperationException e) {
+                if (e instanceof InvocationTargetException) {
+                    Throwable cause = e.getCause();
+                    if(cause instanceof RuntimeException)
+                        throw (RuntimeException)cause;
+                    else
+                        throw new RuntimeException(cause);
+                }
                 throw new RuntimeException(e);
             }
         }
@@ -140,6 +159,13 @@ public class ValueFromMethod {
                 Object ret = method.invoke(null, p0, p1, p2, p3);
                 return returnsVoid ? Tuple0.INSTANCE : ret;
             } catch (ReflectiveOperationException e) {
+                if (e instanceof InvocationTargetException) {
+                    Throwable cause = e.getCause();
+                    if(cause instanceof RuntimeException)
+                        throw (RuntimeException)cause;
+                    else
+                        throw new RuntimeException(cause);
+                }
                 throw new RuntimeException(e);
             }
         }
@@ -178,6 +204,13 @@ public class ValueFromMethod {
                 Object ret =  method.invoke(null, ps);
                 return returnsVoid ? Tuple0.INSTANCE : ret;
             } catch (ReflectiveOperationException e) {
+                if (e instanceof InvocationTargetException) {
+                    Throwable cause = e.getCause();
+                    if(cause instanceof RuntimeException)
+                        throw (RuntimeException)cause;
+                    else
+                        throw new RuntimeException(cause);
+                }
                 throw new RuntimeException(e);
             }
         }