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; } }