package toy;

/**
 * ToyException is an exception passed down internally in the step() function of
 * ToyVirtualMachine.  It signals one of several type of exceptions that can
 * occur in the "strict" TOY machine.
 *
 * @author Brian Tsang
 * @version 7.0
 */

public class ToyException extends Exception
{
    /**
     * The type of exception that occurs when the value of an uninitialized
     * register/memory sector is accessed by an operation.
     * @see #type
     */
    public static final int VARIABLE_UNINITIALIZED = 10;
    /**
     * The type of exception that occurs when the fetch-execute loop attempts to
     * execute the command in an uninitialized memory sector.
     * @see #type
     */
    public static final int COMMAND_UNINITIALIZED  = 11;
    /**
     * The type of exception that occurs when the result of the operation is not
     * representable as a 16-bit two's complement signed integers.
     * @see #type
     */
    public static final int OVERFLOW               = 20;
    /**
     * The type of exception that occurs when a shift operation is commanded to
     * shift further than 000F positions.
     * @see #type
     */
    public static final int SHIFT_OUT_OF_BOUNDS    = 30;
    /**
     * The type of exception that occurs when the program counter exceeds FF.
     * @see #type
     */
    public static final int PC_OUT_OF_BOUNDS       = 31;
    /**
     * The type of exception that occurs when an operator attempts to access a
     * register that is not valid (attempting to assign a value to R[0]).
     * @see #type
     */
    public static final int REGISTER_OUT_OF_BOUNDS = 32;
    /**
     * The type of exception that occurs when an operator attempts to access a
     * memory sector that is not between 0000 and 00FF.
     * @see #type
     */
    public static final int MEM_OUT_OF_BOUNDS      = 33;

    /**
     * The type of this exception.
     * @see #getType()
     * @serial
     */
    int type;

    /**
     * Constructs a new ToyException object of type newType
     */
    public ToyException(int newType)
    {
        type = newType;
    }

    /**
     * Returns the type of this exception.
     * @return the type of this exception
     */
    public int getType()
    {
        return type;
    }
}
