com.google.inject.ProvisionException Maven / Gradle / Ivy
package com.google.inject;
import com.google.common.collect.ImmutableSet;
import com.google.inject.internal.Messages;
import com.google.inject.spi.Message;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Indicates that there was a runtime failure while providing an instance.
*
*/
public final class ProvisionException extends RuntimeException {
private static final long serialVersionUID = 0;
private final ImmutableSet messages;
/**
* Creates a ProvisionException containing {@code messages}.
*/
public ProvisionException(Iterable messages) {
this.messages = ImmutableSet.copyOf(messages);
checkArgument(!this.messages.isEmpty());
initCause(Messages.getOnlyCause(this.messages));
}
public ProvisionException(String message, Throwable cause) {
super(cause);
this.messages = ImmutableSet.of(new Message(message, cause));
}
public ProvisionException(String message) {
this.messages = ImmutableSet.of(new Message(message));
}
/**
* Returns messages for the errors that caused this exception.
*/
public Collection getErrorMessages() {
return messages;
}
@Override
public String getMessage() {
return Messages.formatMessages("Unable to provision, see the following errors", messages);
}
}