]> 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 4efd2a8d404e7037925fd7d005d782e1fa5c8d3f..1c8c6431f89b16310fd41232b8fd580294463215 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.scl.compiler.internal.codegen.utils;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.simantics.scl.runtime.function.FunctionImpl1;
@@ -26,6 +27,13 @@ public class ValueFromMethod {
                 Object ret = method.invoke(null, p0);
                 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);
             }
         }
@@ -63,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);
             }
         }
@@ -100,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);
             }
         }
@@ -137,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);
             }
         }
@@ -175,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);
             }
         }