Below is a detailed description, but I like to avoid reflection and casting. I do not think (but am not sure) that the Java 7 multiple-catch syntax would be useful.
public static Object executeViewComponent(String name, Component c, HttpServletRequest request) throw KnownException_1 , KnownException_2 , ... , KnownException_n { try { return c.getClass() .getMethod(c.getMetaData().getMethod(), HttpServletRequest.class) .invoke(c, request); } catch ( InvocationTargetException cause ) { assert cause . getCause ( ) != null : "Null Cause" ; try { throw cause . getCause ( ) ; } catch ( KnownException_1 c ) { throw c } catch ( KnownException_2 c ) { throw c } ... catch ( KnownException_n c ) { throw c } catch ( RuntimeException c ) { throw c ; } catch ( Error c ) { throw c ; } catch ( Throwable c ) { assert false : "Unknown Cause" ; } } }
emory
source share