Skip to content

Commit e2e6c5c

Browse files
committed
DefaultStartupService: defend against exceptions
A startup operation might throw an unchecked exception. We don't want that to kill the application startup. Rather, let's just log an error.
1 parent 8d3a362 commit e2e6c5c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/org/scijava/startup/DefaultStartupService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.ArrayDeque;
3636
import java.util.Deque;
3737

38+
import org.scijava.log.LogService;
39+
import org.scijava.plugin.Parameter;
3840
import org.scijava.plugin.Plugin;
3941
import org.scijava.service.AbstractService;
4042
import org.scijava.service.Service;
@@ -51,6 +53,9 @@ public class DefaultStartupService extends AbstractService implements
5153

5254
private final Deque<Runnable> operations = new ArrayDeque<>();
5355

56+
@Parameter(required = false)
57+
private LogService log;
58+
5459
@Override
5560
public void addOperation(final Runnable operation) {
5661
operations.add(operation);
@@ -60,7 +65,12 @@ public void addOperation(final Runnable operation) {
6065
public void executeOperations() {
6166
while (!operations.isEmpty()) {
6267
final Runnable operation = operations.pop();
63-
operation.run();
68+
try {
69+
operation.run();
70+
}
71+
catch (final RuntimeException exc) {
72+
if (log != null) log.error(exc);
73+
}
6474
}
6575
}
6676
}

0 commit comments

Comments
 (0)