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             * ID for serialization.
014             */
015            private static final long serialVersionUID = 5720456316151476681L;
016    
017            /**
018         * Indicates that this Exception was thrown because the money in the MoneyBag is less than
019         * the money to be removed.
020         */
021        public static final int NOT_ENOUGH_MONEY = 0;
022    
023        /**
024         * Indicates that this Exception was thrown because it is not possible to sum up the
025         * available money to the amount to be removed.<br>
026         * <br>
027         * Example:<br>
028         * The MoneyBag contains:
029         * <ul>
030         *   <li>5 coins of value 10 cents</li>
031         *   <li>5 coins of value 2 cents</li>
032         * </ul>
033         * Trying to return 11 cents would cause that exception.
034         */
035        public static final int NO_FITTING_UNITS = 1;
036    
037        private int iCause;
038    
039        /**
040         * Creates a new NotEnoughMoneyException.
041         */
042        public NotEnoughMoneyException(int cause) {
043            super();
044            iCause = cause;
045        }
046    
047        /**
048         * Creates a new NotEnoughMoneyException with a detail message.
049         *
050         * @param sDetail the detail message.
051         */
052        public NotEnoughMoneyException(String sDetail, int cause) {
053            super(sDetail);
054            iCause = cause;
055        }
056    
057        /**
058         * Returns the cause for this exception. If there was not enough money, {@link #NOT_ENOUGH_MONEY} is
059         * returned. If there was no way to sum up the money with the coins/bank notes available,
060         * {@link #NO_FITTING_UNITS} is returned.
061         *
062         * @return the cause for this exception
063         */
064        public int cause() {
065            return iCause;
066        }
067    }