InvocationTargetExceptionのターゲット例外をどのように再スローしますか。リフレクションを使用して、クラスの1つでinvoke()メソッドを呼び出すメソッドがあります。ただし、コード内で例外がスローされた場合、InvocationTargetExceptionについては気にせず、ターゲット例外のみが必要です。次に例を示します。
public static Object executeViewComponent(String name, Component c,
HttpServletRequest request) throws Exception {
try {
return c.getClass()
.getMethod(c.getMetaData().getMethod(), HttpServletRequest.class)
.invoke(c, request);
} catch (InvocationTargetException e) {
// throw the target exception here
}
}
私が直面している主な問題は、throw e.getCause();を呼び出すことです。例外をスローしませんが、スロー可能をスローします。おそらく私はこれに間違ってアプローチしていますか?