(refs #7326) Better handling of exceptions in Java->SCL interface 46/646/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 21 Jun 2017 13:23:47 +0000 (16:23 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 21 Jun 2017 13:23:47 +0000 (16:23 +0300)
Change-Id: I31573bc72f48d601c7f92faa491e59594eefdf59

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) {
                 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);
             }
         }
                 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) {
                 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);
             }
         }
                 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) {
                 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);
             }
         }
                 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) {
                 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);
             }
         }
                 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) {
                 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);
             }
         }
                 throw new RuntimeException(e);
             }
         }