001 package data;
002
003 /**
004 * Exception thrown when an error occurs on transferring money from one MoneyBag to another.
005 *
006 * @author Andreas Bartho
007 * @version 3.1
008 * @since v3.1
009 */
010 public class NotEnoughMoneyException extends RuntimeException {
011
012 /**
013 * Indicates that this Exception was thrown because the money in the MoneyBag is less than
014 * the money to be removed.
015 */
016 public static final int NOT_ENOUGH_MONEY = 0;
017
018 /**
019 * Indicates that this Exception was thrown because it is not possible to sum up the
020 * available money to the amount to be removed.<br>
021 * <br>
022 * Example:<br>
023 * The MoneyBag contains:
024 * <ul>
025 * <li>5 coins of value 10 cents</li>
026 * <li>5 coins of value 2 cents</li>
027 * </ul>
028 * Trying to return 11 cents would cause that exception.
029 */
030 public static final int NO_FITTING_UNITS = 1;
031
032 private int iCause;
033
034 /**
035 * Creates a new NotEnoughMoneyException.
036 */
037 public NotEnoughMoneyException(int cause) {
038 super();
039 iCause = cause;
040 }
041
042 /**
043 * Creates a new NotEnoughMoneyException with a detail message.
044 *
045 * @param sDetail the detail message.
046 */
047 public NotEnoughMoneyException(String sDetail, int cause) {
048 super(sDetail);
049 iCause = cause;
050 }
051
052 /**
053 * Returns the cause for this exception. If there was not enough money, {@link #NOT_ENOUGH_MONEY} is
054 * returned. If there was no way to sum up the money with the coins/bank notes available,
055 * {@link #NO_FITTING_UNITS} is returned.
056 *
057 * @return the cause for this exception
058 */
059 public int cause() {
060 return iCause;
061 }
062 }