From 8955eeb70af0cd88735344359ea8b6f0469bfd77 Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Fri, 9 Aug 2024 17:04:07 -0400 Subject: [PATCH] handle exam exceptions --- .../com/primefactorsolutions/service/CompilerService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/service/CompilerService.java b/src/main/java/com/primefactorsolutions/service/CompilerService.java index 43b8608..70b8450 100644 --- a/src/main/java/com/primefactorsolutions/service/CompilerService.java +++ b/src/main/java/com/primefactorsolutions/service/CompilerService.java @@ -4,6 +4,7 @@ import com.primefactorsolutions.service.compiler.InMemoryFileManager; import com.primefactorsolutions.service.compiler.JavaSourceFromString; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import javax.tools.DiagnosticCollector; @@ -49,7 +50,12 @@ public class CompilerService { Method[] methods = clazz.getMethods(); for (Method m : methods) { if ("run".equals(m.getName())) { - results = (Map) m.invoke(null, new Object[] {}); + try { + results = (Map) m.invoke(null, new Object[]{}); + } catch (Exception e) { + results = Map.of("Exception: " + ExceptionUtils.getStackTrace(ExceptionUtils.getRootCause(e)), false); + } + break; } }