From 2cd6506c0358e8040753d99d45a021271abab7ae Mon Sep 17 00:00:00 2001 From: Rongmario Date: Sat, 16 Dec 2023 16:48:41 +0000 Subject: [PATCH] Handle groovy's uncaught exceptions and throwables accordingly (#105) --- .../groovyscript/sandbox/GroovyScriptSandbox.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java index 156f13060..42a16a831 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java @@ -11,6 +11,7 @@ import com.cleanroommc.groovyscript.sandbox.transformer.GroovyScriptCompiler; import groovy.lang.Binding; import groovy.lang.Closure; +import groovy.lang.GroovyRuntimeException; import groovy.util.GroovyScriptEngine; import groovy.util.ResourceException; import groovy.util.ScriptException; @@ -89,11 +90,11 @@ public void run(LoadStage currentLoadStage) { this.currentLoadStage = Objects.requireNonNull(currentLoadStage); try { super.load(); - } catch (IOException | ScriptException | ResourceException e) { - GroovyLog.get().errorMC("An Exception occurred trying to run groovy!"); + } catch (IOException | ScriptException | ResourceException | GroovyRuntimeException e) { + GroovyLog.get().errorMC("An exception occurred while trying to run groovy code!"); GroovyScript.LOGGER.throwing(e); - } catch (Exception e) { - GroovyLog.get().exception(e); + } catch (Throwable t) { + GroovyLog.get().exception(t); } finally { this.currentLoadStage = null; }