package edu.princeton.toy.lang; /** * TExceptionHandler essentially maintains a list of what exceptions to ignore and what exceptions * to propagate throughout the virtual machine (halting the TVM). * * @author btsang * @version 7.1 */ public interface TExceptionHandler { /** * An implementation of TExceptionHandler which ignores all exceptions. */ public static final TExceptionHandler PROMISCUOUS_EXCEPTION_HANDLER = new TExceptionHandler() { public void raise(TExceptionType type) throws TException { if (type == null) throw new NullPointerException(); } public boolean getWillThrow(int index) { if (index < 0 || index >= TExceptionType.TYPES.length) throw new ArrayIndexOutOfBoundsException(); return false; } public boolean getWillThrow(TExceptionType type) { if (type == null) throw new NullPointerException(); return false; } }; /** * An implementation of TExceptionHandler which throws all exceptions. */ public static final TExceptionHandler PRUDISH_EXCEPTION_HANDLER = new TExceptionHandler() { public void raise(TExceptionType type) throws TException { throw new TException(type); } public boolean getWillThrow(int index) { if (index < 0 || index >= TExceptionType.TYPES.length) throw new ArrayIndexOutOfBoundsException(); return true; } public boolean getWillThrow(TExceptionType type) { if (type == null) throw new NullPointerException(); return true; } }; /** * Throws a TException with the specified type iff the specified exception was not set to be * ignored. The Virtual Machine should raise all exceptional conditions and let the handler * decide wheter or not that exception should be propagated through the rest of the machine. * * @param type The type of exceptional condition that was raised in the Virtual Machine. */ public abstract void raise(TExceptionType type) throws TException; /** * Gets wheter or not the handler should throw a raised exception of the specified type. * * @param index The index of type (in the TExceptionType.TYPES array) in question. An invalid * value will result in an ArrayIndexOutOfBoundsException. * @return True iff the handler will throw exceptions of this type. * @see edu.princeton.toy.lang.TExceptionType#TYPES */ public abstract boolean getWillThrow(int index); /** * Gets wheter or not the handler should throw a raised exception of the specified type. * * @param type The type in question. A null value will result in a NullPointerException. * @return True iff the handler will throw exceptions of this type. * @see edu.princeton.toy.lang.TExceptionType#TYPES */ public abstract boolean getWillThrow(TExceptionType type); }