

/**
 * GDI2 B-Tree and file format exception
 */

public class GDI2BTreeFileFormatException extends RuntimeException
{
	private static final long serialVersionUID = 1L;
	
	static public enum GDI2TypeOfException {
		/**
		 * File format is incorrect
		 */
		FILE,

		/**
		 * An error regarding the B-Tree
		 */
		BTREE
	}
	/**
	 * The error message
	 */
	protected String errorMessage;
	/**
	 * The error type
	 */
	protected GDI2TypeOfException errorType;
	/**
	 * Constructor
	 * @param s The message string
	 */
	public GDI2BTreeFileFormatException(String s) {
		super(s);
	}
	/**
	 * Constructor
	 * @param type The type of the error (FILE or BTREE)
	 * @param message The error message
	 */
	public GDI2BTreeFileFormatException(GDI2TypeOfException type, String message)
	{
		errorMessage = message;
		errorType    = type;
	}
	/* (non-Javadoc)
	 * @see java.lang.Throwable#getMessage()
	 */
	@Override
	public String getMessage()
	{
		return "GDI2 B-Tree Error: " + errorMessage;
	}
	/* (non-Javadoc)
	 * @see java.lang.Throwable#toString()
	 */
	@Override
	public String toString() 
	{
		String message = new String();
		if (errorType == GDI2TypeOfException.FILE)
			message = "FileFormatException";
		else if (errorType == GDI2TypeOfException.BTREE)
			message = "BTreeException";
		return "GDI2 B-Tree Error: " + message + " : " + errorMessage;
	}
}
