package error;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * A utility class to hold common exception handling functionality
 */
public class ExceptionUtil {

	private ExceptionUtil() {
		throw new UnsupportedOperationException("Utility class");
	}

	/**
	 * Handle a critical exception, calling system exit with a non zero exit value
	 *
	 * @param e
	 * @param description
	 * @param logger
	 */
	public static void handleCriticalException(Exception e, String description, Logger logger) {
		logger.log(Level.SEVERE, description, e);
		System.exit(1);
	}

	/**
	 * Handle a critical exception, calling system exit with a non zero exit value,
	 * used when logger is not init
	 *
	 * @param e
	 * @param description
	 */
	public static void handleCriticalException(Exception e, String description) {
		System.err.println(description);
		e.printStackTrace();
		System.exit(1);
	}

	/**
	 * Handle a non-critical exception, don't exit
	 *
	 * @param e
	 * @param description
	 * @param logger
	 */
	public static void handleRecoverableException(Exception e, String description, Logger logger) {
		logger.log(Level.WARNING, description, e);
	}
}
