All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.inject.CreationException 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;

/**
 * Thrown when errors occur while creating a {@link Injector}. Includes a list of encountered
 * errors. Clients should catch this exception, log it, and stop execution.
 */
@SuppressWarnings("serial")
public class CreationException extends RuntimeException {

    private final ImmutableSet messages;

    /**
     * Creates a CreationException containing {@code messages}.
     */
    public CreationException(Collection messages) {
        this.messages = ImmutableSet.copyOf(messages);
        checkArgument(!this.messages.isEmpty());
        initCause(Messages.getOnlyCause(this.messages));
    }

    /**
     * Returns messages for the errors that caused this exception.
     */
    public Collection getErrorMessages() {
        return messages;
    }

    @Override
    public String getMessage() {
        return Messages.formatMessages("Unable to create injector, see the following errors", messages);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy