From ade851c7905997045d706e5911cd18fc15323954 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Mon, 7 Aug 2017 14:26:40 +0200
Subject: [PATCH] unify interop exception handling in FFI

---
 .../r/ffi/impl/llvm/TruffleLLVM_C.java        |  5 ++--
 .../r/ffi/impl/llvm/TruffleLLVM_Call.java     | 12 ++++----
 .../r/ffi/impl/llvm/TruffleLLVM_PkgInit.java  | 12 ++++----
 .../r/ffi/impl/llvm/TruffleLLVM_Stats.java    |  9 +++---
 .../r/ffi/impl/llvm/TruffleLLVM_Tools.java    |  5 ++--
 .../r/ffi/impl/llvm/TruffleLLVM_UserRng.java  | 17 +++++------
 .../r/ffi/impl/nfi/TruffleNFI_Call.java       | 28 +++++++++----------
 .../r/ffi/impl/nfi/TruffleNFI_PkgInit.java    | 14 +++++-----
 .../r/ffi/impl/nfi/TruffleNFI_Tools.java      |  4 +--
 .../r/ffi/impl/nfi/TruffleNFI_UserRng.java    | 21 +++++++-------
 10 files changed, 66 insertions(+), 61 deletions(-)

diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_C.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_C.java
index ae1c62d397..5b0c8f546e 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_C.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_C.java
@@ -24,6 +24,7 @@ package com.oracle.truffle.r.ffi.impl.llvm;
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.nodes.Node;
 import com.oracle.truffle.r.ffi.impl.interop.NativeDoubleArray;
@@ -51,8 +52,8 @@ class TruffleLLVM_C implements CRFFI {
                 }
                 assert numArgs == args.length;
                 ForeignAccess.sendExecute(messageNode, nativeCallInfo.address.asTruffleObject(), wargs);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
 
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Call.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Call.java
index c8c93913a0..a60438f16b 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Call.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Call.java
@@ -115,8 +115,8 @@ final class TruffleLLVM_Call implements CallRFFI {
                     } else if (value instanceof TruffleObject) {
                         ForeignAccess.sendExecute(executeNode, INIT_VAR_FUN.OBJ.symbolHandle.asTruffleObject(), i, value);
                     }
-                } catch (Throwable t) {
-                    throw RInternalError.shouldNotReachHere(t);
+                } catch (InteropException ex) {
+                    throw RInternalError.shouldNotReachHere(ex);
                 }
             }
         } finally {
@@ -138,8 +138,8 @@ final class TruffleLLVM_Call implements CallRFFI {
             // llvm specific callbacks
             ForeignAccess.sendExecute(executeNode, symbolHandle.asTruffleObject(), callbacks.length, new BytesToNativeCharArrayCall(upCallsRFFIImpl));
             ForeignAccess.sendExecute(executeNode, symbolHandle.asTruffleObject(), callbacks.length + 1, new CharSXPToNativeArrayCall(upCallsRFFIImpl));
-        } catch (Throwable t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
@@ -231,8 +231,8 @@ final class TruffleLLVM_Call implements CallRFFI {
                     result = unwrap.execute(result);
                 }
                 return result;
-            } catch (InteropException t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             } finally {
                 RContext.getRForeignAccessFactory().setIsNull(isNullSetting);
             }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_PkgInit.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_PkgInit.java
index 62920f9001..8ae6a58474 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_PkgInit.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_PkgInit.java
@@ -23,6 +23,7 @@
 package com.oracle.truffle.r.ffi.impl.llvm;
 
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.interop.TruffleObject;
 import com.oracle.truffle.api.nodes.Node;
@@ -70,8 +71,8 @@ final class TruffleLLVM_PkgInit extends Generic_PkgInit {
             ForeignAccess.sendExecute(executeNode, callbackSymbol, PkgInitUpCalls.Index.forceSymbols.ordinal(), new ForceSymbolsCall(trufflePkgInit));
             ForeignAccess.sendExecute(executeNode, callbackSymbol, PkgInitUpCalls.Index.registerCCallable.ordinal(), new RegisterCCallableCall(trufflePkgInit));
             ForeignAccess.sendExecute(executeNode, callbackSymbol, PkgInitUpCalls.Index.getCCallable.ordinal(), new GetCCallableCall(trufflePkgInit));
-        } catch (Throwable t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
@@ -89,10 +90,9 @@ final class TruffleLLVM_PkgInit extends Generic_PkgInit {
     protected Object setSymbol(DLLInfo dllInfo, int nstOrd, long routines, int index) {
         Node executeNode = Message.createExecute(4).createNode();
         try {
-            Object result = ForeignAccess.sendExecute(executeNode, setSymbolHandle, dllInfo, nstOrd, routines, index);
-            return result;
-        } catch (Throwable t) {
-            throw RInternalError.shouldNotReachHere();
+            return ForeignAccess.sendExecute(executeNode, setSymbolHandle, dllInfo, nstOrd, routines, index);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Stats.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Stats.java
index 21a0da11b4..a0b16fc81a 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Stats.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Stats.java
@@ -26,6 +26,7 @@ import com.oracle.truffle.api.dsl.Cached;
 import com.oracle.truffle.api.dsl.ImportStatic;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.nodes.Node;
 import com.oracle.truffle.r.ffi.impl.interop.NativeDoubleArray;
@@ -85,8 +86,8 @@ public class TruffleLLVM_Stats implements StatsRFFI {
                             NativeDoubleArray nwork = new NativeDoubleArray(work);
                             NativeIntegerArray niwork = new NativeIntegerArray(iwork)) {
                 return (int) ForeignAccess.sendExecute(messageNode, fftWork.asTruffleObject(), na, nseg, n, nspn, isn, nwork, niwork);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
 
@@ -124,8 +125,8 @@ public class TruffleLLVM_Stats implements StatsRFFI {
             try (NativeIntegerArray npmaxf = new NativeIntegerArray(pmaxf);
                             NativeIntegerArray npmaxp = new NativeIntegerArray(pmaxp)) {
                 ForeignAccess.sendExecute(messageNode, fftFactor.asTruffleObject(), n, npmaxf, npmaxp);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
 
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java
index b04deaa0d0..329e14e3f7 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Tools.java
@@ -23,6 +23,7 @@
 package com.oracle.truffle.r.ffi.impl.llvm;
 
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.interop.TruffleObject;
 import com.oracle.truffle.api.nodes.Node;
@@ -48,8 +49,8 @@ public class TruffleLLVM_Tools implements ToolsRFFI {
             try {
                 ForeignAccess.sendExecute(executeNode, callbackSymbol, new RConnGetCCall());
                 addCallbackDone = true;
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_UserRng.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_UserRng.java
index 63cdf62864..a3a276221a 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_UserRng.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_UserRng.java
@@ -25,6 +25,7 @@ package com.oracle.truffle.r.ffi.impl.llvm;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.nodes.Node;
 import com.oracle.truffle.r.runtime.RInternalError;
@@ -53,8 +54,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
             init(1);
             try {
                 ForeignAccess.sendExecute(message, Function.Init.getSymbolHandle().asTruffleObject(), seed);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -67,8 +68,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
             try {
                 Object address = ForeignAccess.sendExecute(message, Function.Rand.getSymbolHandle().asTruffleObject());
                 return (double) ForeignAccess.sendExecute(readPointerNode, TruffleLLVM_CAccess.Function.READ_POINTER_DOUBLE.getSymbolHandle().asTruffleObject(), address);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -81,8 +82,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
             try {
                 Object address = ForeignAccess.sendExecute(message, Function.NSeed.getSymbolHandle().asTruffleObject());
                 return (int) ForeignAccess.sendExecute(readPointerNode, TruffleLLVM_CAccess.Function.READ_POINTER_INT.getSymbolHandle().asTruffleObject(), address);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -98,8 +99,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
                     Object seed = ForeignAccess.sendExecute(readPointerNode, TruffleLLVM_CAccess.Function.READ_ARRAY_INT.getSymbolHandle().asTruffleObject(), address, i);
                     n[i] = (int) seed;
                 }
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Call.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Call.java
index fb8810b3a6..799d8b5699 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Call.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Call.java
@@ -85,8 +85,8 @@ public class TruffleNFI_Call implements CallRFFI {
             SymbolHandle symbolHandle = DLL.findSymbol(initVarFun.funName, null); // libR
             try {
                 initVarFun.initFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", initVarFun.signature);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
         Node executeNode = Message.createExecute(2).createNode();
@@ -109,8 +109,8 @@ public class TruffleNFI_Call implements CallRFFI {
                     } else {
                         ForeignAccess.sendExecute(executeNode, INIT_VAR_FUN.OBJ.initFunction, i, value);
                     }
-                } catch (Throwable t) {
-                    throw RInternalError.shouldNotReachHere(t);
+                } catch (InteropException ex) {
+                    throw RInternalError.shouldNotReachHere(ex);
                 }
             }
         } finally {
@@ -130,8 +130,8 @@ public class TruffleNFI_Call implements CallRFFI {
                 TruffleObject addCallbackFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", addCallbackSignature);
                 ForeignAccess.sendExecute(executeNode, addCallbackFunction, callback.ordinal(), callback.call);
             }
-        } catch (Throwable t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
@@ -162,8 +162,8 @@ public class TruffleNFI_Call implements CallRFFI {
             SymbolHandle symbolHandle = DLL.findSymbol(returnArrayFun.funName, null); // libR
             try {
                 returnArrayFun.function = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", returnArrayFun.signature);
-            } catch (InteropException t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -181,8 +181,8 @@ public class TruffleNFI_Call implements CallRFFI {
             } else {
                 throw RInternalError.shouldNotReachHere();
             }
-        } catch (InteropException t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
@@ -204,8 +204,8 @@ public class TruffleNFI_Call implements CallRFFI {
                     throw RInternalError.shouldNotReachHere();
 
             }
-        } catch (InteropException t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
@@ -213,8 +213,8 @@ public class TruffleNFI_Call implements CallRFFI {
         Node executeNode = Message.createExecute(1).createNode();
         try {
             ForeignAccess.sendExecute(executeNode, ReturnArray.FREE.function, address);
-        } catch (InteropException t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_PkgInit.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_PkgInit.java
index e8dd18db02..e35a96709c 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_PkgInit.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_PkgInit.java
@@ -23,6 +23,7 @@
 package com.oracle.truffle.r.ffi.impl.nfi;
 
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.interop.TruffleObject;
 import com.oracle.truffle.api.nodes.Node;
@@ -84,8 +85,8 @@ public final class TruffleNFI_PkgInit extends Generic_PkgInit {
             }
             symbolHandle = DLL.findSymbol("Rdynload_setSymbol", null);
             setSymbolFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", SETSYMBOL_SIGNATURE);
-        } catch (Throwable t) {
-            throw RInternalError.shouldNotReachHere(t);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 
@@ -100,13 +101,12 @@ public final class TruffleNFI_PkgInit extends Generic_PkgInit {
     }
 
     @Override
-    protected Object setSymbol(DLLInfo dllInfo, int nstOrd, long routines, int index) {
+    protected DotSymbol setSymbol(DLLInfo dllInfo, int nstOrd, long routines, int index) {
         Node executeNode = Message.createExecute(4).createNode();
         try {
-            DotSymbol result = (DotSymbol) ForeignAccess.sendExecute(executeNode, setSymbolFunction, dllInfo, nstOrd, routines, index);
-            return result;
-        } catch (Throwable t) {
-            throw RInternalError.shouldNotReachHere(t);
+            return (DotSymbol) ForeignAccess.sendExecute(executeNode, setSymbolFunction, dllInfo, nstOrd, routines, index);
+        } catch (InteropException ex) {
+            throw RInternalError.shouldNotReachHere(ex);
         }
     }
 }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java
index d9fa3345f7..30b9bcb94c 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Tools.java
@@ -67,8 +67,8 @@ public class TruffleNFI_Tools implements ToolsRFFI {
             try {
                 TruffleObject function = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", "(env, (object): sint32): void");
                 ForeignAccess.sendExecute(executeNode, function, new RConnGetCCall());
-            } catch (InteropException t) {
-                throw RInternalError.shouldNotReachHere(t);
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_UserRng.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_UserRng.java
index e68c870b4a..f348ec0d0f 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_UserRng.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_UserRng.java
@@ -25,6 +25,7 @@ package com.oracle.truffle.r.ffi.impl.nfi;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
 import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.InteropException;
 import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.interop.TruffleObject;
 import com.oracle.truffle.api.nodes.Node;
@@ -50,8 +51,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
                 Node bind = Message.createInvoke(1).createNode();
                 try {
                     targetFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, function.getSymbolHandle().asTruffleObject(), "bind", signature);
-                } catch (Throwable t) {
-                    throw RInternalError.shouldNotReachHere();
+                } catch (InteropException ex) {
+                    throw RInternalError.shouldNotReachHere(ex);
                 }
             }
         }
@@ -64,8 +65,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
             init(Function.Init, "(sint32): void");
             try {
                 ForeignAccess.sendExecute(message, targetFunction, seed);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -78,8 +79,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
             try {
                 Object address = ForeignAccess.sendExecute(message, targetFunction);
                 return (double) ForeignAccess.sendExecute(readPointerNode, TruffleNFI_CAccess.Function.READ_POINTER_DOUBLE.getSymbolFunction(), address);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -92,8 +93,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
             try {
                 Object address = ForeignAccess.sendExecute(message, targetFunction);
                 return (int) ForeignAccess.sendExecute(readPointerNode, TruffleNFI_CAccess.Function.READ_POINTER_INT.getSymbolFunction(), address);
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
@@ -108,8 +109,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
                 for (int i = 0; i < n.length; i++) {
                     n[i] = (int) ForeignAccess.sendExecute(readPointerNode, TruffleNFI_CAccess.Function.READ_ARRAY_INT.getSymbolFunction(), address, i);
                 }
-            } catch (Throwable t) {
-                throw RInternalError.shouldNotReachHere();
+            } catch (InteropException ex) {
+                throw RInternalError.shouldNotReachHere(ex);
             }
         }
     }
-- 
GitLab