Catch exceptions thrown by context calculators
This commit is contained in:
parent
9d780ae24a
commit
99c6fe20c2
@ -48,7 +48,12 @@ public class ContextManager<T> {
|
|||||||
|
|
||||||
private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) {
|
private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) {
|
||||||
for (ContextCalculator<T> calculator : calculators) {
|
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;
|
return accumulator;
|
||||||
}
|
}
|
||||||
|
@ -39,14 +39,19 @@ import java.util.Set;
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SpongeCalculatorLink implements ContextCalculator<Subject> {
|
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
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||||
Set<Context> contexts = new HashSet<>();
|
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;
|
return accumulator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user