handle exam exceptions

This commit is contained in:
alex 2024-08-09 17:04:07 -04:00
parent ed9cc26831
commit 8955eeb70a

View File

@ -4,6 +4,7 @@ import com.primefactorsolutions.service.compiler.InMemoryFileManager;
import com.primefactorsolutions.service.compiler.JavaSourceFromString; import com.primefactorsolutions.service.compiler.JavaSourceFromString;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticCollector;
@ -49,7 +50,12 @@ public class CompilerService {
Method[] methods = clazz.getMethods(); Method[] methods = clazz.getMethods();
for (Method m : methods) { for (Method m : methods) {
if ("run".equals(m.getName())) { if ("run".equals(m.getName())) {
try {
results = (Map<String, Boolean>) m.invoke(null, new Object[]{}); results = (Map<String, Boolean>) m.invoke(null, new Object[]{});
} catch (Exception e) {
results = Map.of("Exception: " + ExceptionUtils.getStackTrace(ExceptionUtils.getRootCause(e)), false);
}
break; break;
} }
} }