From 29a9155f55ac9ccaef1b3fd163e7c4230fcd4d1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 21 Jun 2017 16:23:47 +0300 Subject: [PATCH] (refs #7326) Better handling of exceptions in Java->SCL interface Change-Id: I31573bc72f48d601c7f92faa491e59594eefdf59 --- .../codegen/utils/ValueFromMethod.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java index 70160dee2..1c8c6431f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java @@ -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); } } -- 2.47.1