edu.rice.cs.plt.reflect
Class ReflectExceptionVisitor<T>

java.lang.Object
  extended by edu.rice.cs.plt.reflect.ReflectExceptionVisitor<T>

public abstract class ReflectExceptionVisitor<T>
extends Object

A visitor for ReflectExceptions. By default, each method simply defers to the defaultCase(java.lang.Exception) method. An implementation should define defaultCase and override any methods corresponding to exceptions that deserve special treatment.

If, as is often the case in exception handling, no return value is required, the return type can be specified as Void, and all methods should simply return null.


Constructor Summary
ReflectExceptionVisitor()
           
 
Method Summary
protected abstract  T defaultCase(Exception e)
           
 T forClassCast(ClassCastException e)
          Handle a ClassCastException, which can occur when attempting to dynamically cast an object to the generic type of a class object.
 T forClassNotFound(ClassNotFoundException e)
          Handle a ClassNotFoundException, which can occur if a class name does not refer to any available classes.
 T forIllegalAccess(IllegalAccessException e)
          Handle an IllegalAccessException, which occurs when an attempt is made to write to a final field or to access an inaccessible class or class member.
 T forIllegalArgument(IllegalArgumentException e)
          Handle an IllegalArgumentException, which can occur if an object whose member is being accessed does not have the required type, or if the arguments to a method or constructor do not match the required signature.
 T forInstantiation(InstantiationException e)
          Handle an InstantiationException, which can occur if an attempt is made to construct a non-constructable class (such as an abstract class).
 T forInvocationTarget(InvocationTargetException e)
          Handle an InvocationTargetException, which occurs whenever a Throwable is thrown by a reflectively-executed method or constructor.
 T forNoSuchField(NoSuchFieldException e)
          Handle a NoSuchFieldException, which can occur when a field name does not refer to a publicly-accessible field of a class.
 T forNoSuchMethod(NoSuchMethodException e)
          Handle a NoSuchMethodException, which can occur when a method or constructor name and signature do not refer to a publicly-accessible method of a class.
 T forNullPointer(NullPointerException e)
          Handle a NullPointerException, which can occur when statically accessing a non-static member, or when attempting to access a member of the object null.
 T forSecurity(SecurityException e)
          Handle a SecurityException, which can occur whenever a security manager restricts access to reflection operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectExceptionVisitor

public ReflectExceptionVisitor()
Method Detail

defaultCase

protected abstract T defaultCase(Exception e)

forClassNotFound

public T forClassNotFound(ClassNotFoundException e)
Handle a ClassNotFoundException, which can occur if a class name does not refer to any available classes.


forNoSuchField

public T forNoSuchField(NoSuchFieldException e)
Handle a NoSuchFieldException, which can occur when a field name does not refer to a publicly-accessible field of a class.


forNoSuchMethod

public T forNoSuchMethod(NoSuchMethodException e)
Handle a NoSuchMethodException, which can occur when a method or constructor name and signature do not refer to a publicly-accessible method of a class.


forIllegalArgument

public T forIllegalArgument(IllegalArgumentException e)
Handle an IllegalArgumentException, which can occur if an object whose member is being accessed does not have the required type, or if the arguments to a method or constructor do not match the required signature. (It can also occur in the rare circumstance that an accessible enum constructor reflectively is invoked.)


forNullPointer

public T forNullPointer(NullPointerException e)
Handle a NullPointerException, which can occur when statically accessing a non-static member, or when attempting to access a member of the object null.


forClassCast

public T forClassCast(ClassCastException e)
Handle a ClassCastException, which can occur when attempting to dynamically cast an object to the generic type of a class object.

See Also:
ReflectUtil.cast(java.lang.Class, java.lang.Object)

forInvocationTarget

public T forInvocationTarget(InvocationTargetException e)
Handle an InvocationTargetException, which occurs whenever a Throwable is thrown by a reflectively-executed method or constructor. Note that all throwables are wrapped in this way, and so a good practice would be to re-throw any that are unexpected (such as errors). Because InvocationTargetException allows construction without a cause parameter, e.getCause() may be null.


forInstantiation

public T forInstantiation(InstantiationException e)
Handle an InstantiationException, which can occur if an attempt is made to construct a non-constructable class (such as an abstract class).


forIllegalAccess

public T forIllegalAccess(IllegalAccessException e)
Handle an IllegalAccessException, which occurs when an attempt is made to write to a final field or to access an inaccessible class or class member.


forSecurity

public T forSecurity(SecurityException e)
Handle a SecurityException, which can occur whenever a security manager restricts access to reflection operations.