Catch exceptions thrown by context calculators

This commit is contained in:
Luck 2017-05-16 13:50:28 +01:00
parent 9d780ae24a
commit 99c6fe20c2
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 14 additions and 4 deletions

View File

@ -48,7 +48,12 @@ public class ContextManager<T> {
private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) {
for (ContextCalculator<T> calculator : calculators) {
calculator.giveApplicableContext(subject, accumulator);
try {
calculator.giveApplicableContext(subject, accumulator);
} catch (Exception e) {
new RuntimeException("Exception thrown by ContextCalculator: " + calculator.getClass().getName(), e).printStackTrace();
}
}
return accumulator;
}

View File

@ -39,14 +39,19 @@ import java.util.Set;
@AllArgsConstructor
public class SpongeCalculatorLink implements ContextCalculator<Subject> {
private final org.spongepowered.api.service.context.ContextCalculator<Subject> calculator;
private final org.spongepowered.api.service.context.ContextCalculator<Subject> delegate;
@Override
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
Set<Context> contexts = new HashSet<>();
calculator.accumulateContexts(subject, contexts);
accumulator.addAll(CompatibilityUtil.convertContexts(contexts));
try {
delegate.accumulateContexts(subject, contexts);
accumulator.addAll(CompatibilityUtil.convertContexts(contexts));
} catch (Exception e) {
new RuntimeException("Exception thrown by delegate Sponge calculator: " + delegate.getClass().getName(), e).printStackTrace();
}
return accumulator;
}
}