Code example for InvocationTargetException

Methods: getCause

        try { 
            return (Class<?>)findClassMethod.invoke(jarLoader, name);
        catch (InvocationTargetException e) {
           throw (Exception)e.getCause();
    /** Trying to find a class that we fail to preload should throw a CNFE. */ 
    public final void testFindClass_classNotFound() throws Exception { 
        try { 
            // Will throw ClassNotFoundException 
            _findClass(mFrameworkClassLoader, "not.a.valid.ClassName");  //$NON-NLS-1$
        } catch (ClassNotFoundException e) {
            // check the message in the CNFE 
            assertEquals("not.a.valid.ClassName", e.getMessage());  //$NON-NLS-1$
        // Exception not thrown - this is a failure 
Contextual code suggestions in your IDE  Get Codota for Java