IMHO the most egregious use of ChekedExceptions is in Javas Reflection API, 
and I cry when I think how beautiful it could have been verses how 
cumbersome reflection can be (My SmallTalk friends laugh about it)

(To construct an instance of an object and then call a method on it)

try
        {
           Class clazz = Class.forName( className );
           Class[] ctorParams = {String.class, String.class, Integer.TYPE};
           Constructor ctor = clazz.getConstructor(ctorParams);
           Object person = ctor.newInstance("lastName", "firstName", 20 );
           Method toStringMethod = clazz.getDeclaredMethod(methodName);
           System.out.println( toStringMethod.invoke(person) );
        }        
        catch( ClassNotFoundException cnfEx )
        {
        }
        catch( NoSuchMethodException nsmEx )
        {
         
        }
        catch( IllegalAccessException illAccEx )
        {
         
        }
        catch( InvocationTargetException invokeTargetEx )
        {
         
        }
        catch( InstantiationException ctorEx )
        {
         
        } 
Granted, this changed in Java 7 (all those exceptions are subclasses of 
ReflectiveOperationException)
try
        {
           Class clazz = Class.forName( className );
           Class[] ctorParams = {String.class, String.class, Integer.TYPE};
           Constructor ctor = clazz.getConstructor(ctorParams);
           Object person = ctor.newInstance("lastName", "firstName", 20 );
           Method toStringMethod = clazz.getDeclaredMethod(methodName);
           System.out.println( toStringMethod.invoke(person) );
        }        
        catch( ReflectiveOperationException re )
        {
        }
But still, I think given how widely used a language feature like Reflection 
is, and how many Libraries, Tools, and Frameworks use Reflection... this 
was just a terrible API design (along with JDBC)

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to